[Import] use of mssql full-text retrieval CONTAINS.

Source: Internet
Author: User
Full-text index-CONTAINS syntax
We usually use CONTAINS in the Where clause, like this: Select * FROM table_name Where CONTAINS (fullText_column, 'search CONTENTS ').

Let's take an example to learn about it. Suppose there is a table students, where the address is a full text retrieval column.
1. query student addresses in Beijing
Select student_id, student_name
FROM students
Where CONTAINS (address, 'beijing ')
Remark: beijing is a word that must be enclosed in single quotes.

2. query student addresses in Hebei Province
Select student_id, student_name
FROM students
Where CONTAINS (address, '"HEIBEI province "')
Remark: HEBEI province is a phrase that must be enclosed in double quotation marks.

3. query student addresses 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. query the addresses with the words "Nanjing Road"
Select student_id, student_name
FROM students
Where CONTAINS (address, 'nanjing NEAR road ')
Remark: The above query will return addresses that contain the words "nanjing road", "nanjing east road", and "nanjing west road.
A near B indicates that A is near B.

5. query the address starting with 'hu '.
Select student_id, student_name
FROM students
Where CONTAINS (address, '"hu *"')
Remark: The preceding query returns an address containing the words 'hubei' and 'hunanc.
Remember: *, not %.

6. Weighted queries
Select student_id, student_name
FROM students
Where CONTAINS (address, 'isabout (city weight (. 8), county wright (. 4 ))')
Remark: ISABOUT is the keyword of this query. weight specifies a value ranging from 0 ~ The number between 1, similar to the coefficient (I understand ). Indicates that different conditions have different focuses.

7. multi-state query of words
Select student_id, student_name
FROM students
Where CONTAINS (address, 'formsof (INFLECTIONAL, street )')
Remark: The query returns the addresses that contain the words 'street 'and 'streets.
For a verb, different tenses are returned, such as dry, dry, dried, drying, and so on.

All of the above examples use English, not Chinese because some query methods do not support Chinese, and my computer is an English system.
Full-text index-CONTAINS syntax
We usually use CONTAINS in the Where clause, like this: Select * FROM table_name Where CONTAINS (fullText_column, 'search CONTENTS ').

Let's take an example to learn about it. Suppose there is a table students, where the address is a full text retrieval column.
1. query student addresses in Beijing
Select student_id, student_name
FROM students
Where CONTAINS (address, 'beijing ')
Remark: beijing is a word that must be enclosed in single quotes.

2. query student addresses in Hebei Province
Select student_id, student_name
FROM students
Where CONTAINS (address, '"HEIBEI province "')
Remark: HEBEI province is a phrase that must be enclosed in double quotation marks.

3. query student addresses 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. query the addresses with the words "Nanjing Road"
Select student_id, student_name
FROM students
Where CONTAINS (address, 'nanjing NEAR road ')
Remark: The above query will return addresses that contain the words "nanjing road", "nanjing east road", and "nanjing west road.
A near B indicates that A is near B.

5. query the address starting with 'hu '.
Select student_id, student_name
FROM students
Where CONTAINS (address, '"hu *"')
Remark: The preceding query returns an address containing the words 'hubei' and 'hunanc.
Remember: *, not %.

6. Weighted queries
Select student_id, student_name
FROM students
Where CONTAINS (address, 'isabout (city weight (. 8), county wright (. 4 ))')
Remark: ISABOUT is the keyword of this query. weight specifies a value ranging from 0 ~ The number between 1, similar to the coefficient (I understand ). Indicates that different conditions have different focuses.

7. multi-state query of words
Select student_id, student_name
FROM students
Where CONTAINS (address, 'formsof (INFLECTIONAL, street )')
Remark: The query returns the addresses that contain the words 'street 'and 'streets.
For a verb, different tenses are returned, such as dry, dry, dried, drying, and so on.

All of the above examples use English, not Chinese because some query methods do not support Chinese, and my computer is an English system.
Source: http://www.nbman.cn/default.asp? Id = 97

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.