全文检索查询
在一个表中创建了全文索引后 才可以对表中的数据进行全文检索Full-Text Catalogs 进行全文检索需要在 SELECT 命令的 WHERE 字句中使用两个 Transact-SQL 谓词 CONTAINS 和 FRETEXT
1、CONTAINS
CONTAINS 谓词的语法如下
CONTAINS ( { column_name | * } , '< contains_search_condition >' )
< contains_search_condition > ::=
{ < simple_term >
| < prefix_term >
| < generation_term >
| < proximity_term >
| < weighted_term >
}
| { ( < contains_search_condition > )
{ AND | AND NOT | OR } < contains_search_condition > [ ...n ]
}
select *
from firms
where contains(f_intro, ' " science and technology " or " information " ')
select *
from firms
where contains(f_name, ' "infor*" ')
select *
from firms
where contains(f_intro, ' "software" NEAR "company" ')
select *
from firms
where contains(f_intro, ' formsof (inflectional, limit) ') /*查找limit及其变体单词中,如limits*/
2、FREETEXT
FREETEXT 谓词的语法如下
FREETEXT ( { column_name | * } , 'freetext_string' )
FREETEXT 谓词的含义与 CONTAINS 类似 但它比 CONTAINS 谓词功能弱 只支持纯文字的搜索 即 freetext_string 只能为单词 短语或句子 而不能使用逻辑表达式等
例 查找公司名称中含有 Management Information System 短语的公司信息
select *
from firms
where contains(firm_name, ‘Management Information System’)
例 查找公司介绍中含有 It’s an excellent company. 句子的公司信息
select *
from firms
where contains(firm_intro, ‘It’s an excellent company.’)