搜索与另一个词或短语邻近的词或短语(邻近词)

可以搜索与另一个词或短语邻近的词或短语。此外,这两个词或短语可以以任意顺序指定,其结果是一样的。下例将搜索与词“bracket”邻近的词“reflector”。

USE AdventureWorks;
GO
SELECT DocumentID, DocumentSummary, Document
FROM Production.Document AS DocTable INNER JOIN
CONTAINSTABLE(Production.Document, Document, '(Reflector NEAR Bracket)' ) AS KEY_TBL
ON DocTable.DocumentID = KEY_TBL.[KEY]
ORDER BY KEY_TBL.RANK;
GO

注意,也可以在 CONTAINSTABLE 中反转词条,所得到的结果相同:

CONTAINSTABLE(Production.Document, Document, '(Bracket NEAR Reflector)' ) AS KEY_TBL

可以用字符 ~ 来代替前面查询中的 NEAR 关键字,其结果是一样的:

CONTAINSTABLE(Production.Document, Document, '(Reflector ~ Bracket)' ) AS KEY_TBL

可以在搜索条件中指定两个以上的词或短语。例如,可以这样:

CONTAINSTABLE(Production.Document, Document, '(Reflector ~ Bracket ~ Installation)' ) AS KEY_TBL

这表示“Reflector”应当邻近“Bracket”,并且“Bracket”应当邻近“Installation”。

请参阅

概念

全文搜索查询

其他资源

CONTAINS (Transact-SQL)
WHERE (Transact-SQL)

帮助和信息

获取 SQL Server 2005 帮助