SQL Server 全文搜索使用 CONTAINS、FORMSOF、NEAR 进行多个搜索词
我是 SQL Server 全文搜索的新手,并且正在尝试找出使用屈折引擎搜索多个单词的最佳方法,以便搜索使用所有单词的各种形式。
据我所知,FREETEXT 在与多个单词一起使用时使用隐式 OR。我想要一个 AND 以便搜索结果包含所有单词,因此我选择使用 CONTAINS。
我正在尝试执行类似于下面的查询的操作,该查询使用 FORMSOF 和邻近关键字 NEAR 来表示多个单词。请注意,这不是有效的语法并返回错误:
select top 5 *
from content
WHERE CONTAINS((Title,Subtitle,Body), 'FORMSOF(INFLECTIONAL, model NEAR airplane)')
但是,下面的查询有效,但我不知道它是否给出了预期的结果。 SQL 全文搜索的“AND”和“NEAR”有区别吗?
select top 5 *
from content
WHERE CONTAINS((Title,Subtitle,Body), 'FORMSOF(INFLECTIONAL, model) AND FORMSOF(INFLECTIONAL, airplane)')
我想我要问的是,有没有办法将 CONTAINS、FORMSOF 和 NEAR 与多个搜索词一起使用?或者我应该只使用上面使用“AND”的第二个查询?
I am new to SQL Server Full Text Searching, and am trying to figure out the best way to search on multiple words using the inflectional engine so the search uses the various forms of all of the words.
From what I read, FREETEXT uses an implicit OR when used with multiple words. I want an AND so that the search results contain all of the words, so because of this I am choosing to use CONTAINS.
I am trying to do something like the query below, which uses FORMSOF with the proximity keyword NEAR for multiple words. Note that this is not valid syntax and returns an error:
select top 5 *
from content
WHERE CONTAINS((Title,Subtitle,Body), 'FORMSOF(INFLECTIONAL, model NEAR airplane)')
However, the query below works, but I don't know if it gives the intended results. Is there a difference between "AND" and "NEAR" with SQL Full Text Search?
select top 5 *
from content
WHERE CONTAINS((Title,Subtitle,Body), 'FORMSOF(INFLECTIONAL, model) AND FORMSOF(INFLECTIONAL, airplane)')
I guess what I am asking is, is there a way to use CONTAINS, FORMSOF, and NEAR with multiple search words? Or should I just use the second query above that uses "AND"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从文档中:
这意味着您可以对(可能有前缀的)单词、短语及其组合使用
NEAR
谓词。由于您的搜索词使用非常简单的规则进行变形,因此您可以仅使用前缀:
或使用
AND
并在客户端进行精细过滤From the docs:
This means you can use
NEAR
predicate for (possible prefixed) words, phrases and their combinations.Since your search terms are inflected using quite simple rules, you can just use prefixes:
or use
AND
and do fine filtering on the client side