CONTAINS syntax
We usually use CONTAINS in the WHERE clause, like this: SELECT * FROM table_name WHERE
CONTAINS(fullText_column,'search contents').
We learn through examples. Suppose there is a table students, in which
address is the column for full-text search.
1. Query students whose address is in Beijing
SELECT student_id,student_name
FROM
students
WHERE CONTAINS( address, 'beijing' )
remark:
beijing is a word and should be enclosed in single quotes.
2. Query students whose address is in Hebei Province
SELECT
student_id,student_name
FROM students
WHERE CONTAINS( address, '"HEIBEI PRovince"' )
remark: HEBEI
Province is a phrase and must be enclosed in double quotes within single quotes.
3. Check for students whose address is in Hebei Province or Beijing
SELECT
student_id,student_name
FROM students
WHERE CONTAINS( address, '"HEIBEI
province" OR beijing' )
remark: You can specify logical operators (including AND, AND NOT, OR).
4. The query has
Address with the words 'Nanjing Road'
SELECT student_id,student_name
FROM students
WHERE
CONTAINS( address, 'nanjing NEAR road' )
remark: The above query will return items containing 'nanjing
road', 'nanjing east road', 'nanjing west road' and other words address.
A NEAR
B means condition: A is close to B.
5. Query addresses starting with 'lake'
SELECT
student_id,student_name
FROM students
WHERE CONTAINS( address, '"hu*"'
)
remark: The above query will return addresses containing the words 'hubei', 'hunan', etc.
Remember it’s *, it’s not
%.
6. Similar weighted query
SELECT student_id,student_name
FROM students
WHERE
CONTAINS( address, 'ISABOUT (city weight (.8), county wright (.4))' )
remark:
ISABOUT is the keyword for this kind of query, and weight specifies a number between 0 and 1, similar to a coefficient (my understanding). Indicates that different conditions have different emphasis.
7.
Polymorphic query of words
SELECT student_id,student_name
FROM students
WHERE CONTAINS(
address, 'FORMSOF (INFLECTIONAL,street)' )
remark: The query will return
Addresses with the words 'street', 'streets', etc.回 For the verb will return to its different tense, such as: DRY, it will return to DRY, DRIED, DRYING
etc.
The above examples are all in English. Chinese is not used because some query methods are not supported in Chinese, and my computer is an English system.