Is it possible to combine NEAR and FORMSOF together in a fulltext search?

陌路散爱 提交于 2019-12-12 09:56:56

问题


I have this:

SELECT * FROM AwesomePeople WHERE CONTAINS(Name, 'NEAR(("Nathan", "Fillion"), MAX, TRUE)')

But I want to combine it so it uses my thesaurus of words to look at alternatives for Nathan and Fillion.

I can do this:

SELECT * FROM AwesomePeople WHERE CONTAINS(Name, 'FORMSOF (THESAURUS, "Nathan"))

But I don't know how to search for 2 words, or make it do FORMSOF and NEAR together in a single query. I have tried a few combinations but am out of luck.

Any ideas?


回答1:


It looks like you are using SQL Server 2012 as 'NEAR(("Nathan", "Fillion") is the newer form of proximity search, called custom proximity search.

From technet: http://technet.microsoft.com/en-us/library/ms142568%28v=sql.110%29.aspx

You cannot combine a custom proximity term with a generic proximity term (term1 NEAR term2), a generation term (ISABOUT …), or a weighted term (FORMSOF …).

and also lower down

You cannot combine a generic proximity term with a custom proximity term, such as NEAR((term1,term2),5), a weighted term (ISABOUT …), or a generational term (FORMSOF …).

Technet seems to have the ISABOUT and FORMSOF mixed up in the first quote, but either way ISABOUT or FORMSOF terms cannot be combined with a NEAR term.




回答2:


Following will work great. It is more powerful.

SELECT  * FROM AwesomePeople AS C INNER JOIN
CONTAINSTABLE(AwesomePeople ,name, 'ISABOUT (
    FORMSOF(Thesaurus, "Nathan"),
    FORMSOF(Thesaurus, "Fillion"))') AS K
ON C.ID = K.[KEY];


来源:https://stackoverflow.com/questions/20682825/is-it-possible-to-combine-near-and-formsof-together-in-a-fulltext-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!