SQL Server Full Text Search matches part of a word, even without wildcard

时光毁灭记忆、已成空白 提交于 2020-01-15 09:31:12

问题


Take this query:

SELECT * FROM Books
WHERE CONTAINS(([Description], ReverseDescription), '"øgle"')

And these two text for the columns being search:

http://textuploader.com/5bg5r

http://textuploader.com/5bg59

Why does that one match? I cannot for find an exact match in either of those texts. And as far as I know only the partial match should show up if I use the following query:

SELECT * FROM Books
WHERE CONTAINS(([Description], ReverseDescription), '"øgle*"')

Anyone know what's going on?


回答1:


Full-Text works on selected language grammar and vocabulary basis, not on simple character comparison like LIKE would do. Each language defines stemmers and word breakers. I can't say weather øgle is a full word by itself and how is your FT index treating that ø. My suspicion is that your index is not created with Danish language rules. If your index is indeed using the correct language, then you need to check the stemmer and breakers rules in use for that language.

Update

Actually I think is simpler. The presence of "" makes the search term a prefix term, event without an *. MSDN is a bit ambiguous here, because for example in Performing Prefix Searches it states:

When the prefix term is a phrase, each token making up the phrase is considered a separate prefix term. All rows that have words beginning with the prefix terms will be returned. For example, the prefix term "light bread*" will find rows with text of either "light breaded," "lightly breaded," or "light bread", but will not return "Lightly toasted bread".

Note how light in the example is a prefix and does not require light*. I do not have a system to test, so is a bit of speculation on my side, but I suspect that CONTAINS will consider "øgle" as a case insensitive prefix search and then your text contains two matches for Øgledronning and Øgledronningens.




回答2:


Change COLLATE Latin1_General_CS_AS

for example query will look like

    SELECT * FROM Books
       WHERE CONTAINS(([Description], ReverseDescription), '"øgle*"')
     AND [Description] COLLATE Latin1_General_CS_AS LIKE '%"øgle*"%' 


来源:https://stackoverflow.com/questions/37586610/sql-server-full-text-search-matches-part-of-a-word-even-without-wildcard

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