Strange behaviour with Fulltext search in SQL Server

喜夏-厌秋 提交于 2019-12-22 04:12:33

问题


I have MyTable with a Column Message NVARCHAR(MAX).

Record with ID 1 contains the Message '0123456789333444 Test'

When I run the following query

DECLARE @Keyword NVARCHAR(100)

SET @Keyword = '0123456789000001*'

SELECT *
FROM MyTable
WHERE CONTAINS(Message, @Keyword) 

Record ID 1 is showing up in the results and in my opinion it should not because 0123456789333444 does not contains 0123456789000001.

Can someone explain why the records is showing up anyway?

EDIT

select * from sys.dm_fts_parser('"0123456789333444 Test"',1033,0,0)

returns the following:

group_id phrase_id occurrence special_term  display_term        expansion_type source_term
1        0         1           Exact Match  0123456789333444    0              0123456789333444 Test
1        0         1           Exact Match  nn0123456789333444  0              0123456789333444 Test
1        0         2           Exact Match  test                0              0123456789333444 Test

回答1:


This is because the @Keyword is not wrapped in double quotes. Which forces zero, one, or more matches.

Specifies a match of words or phrases beginning with the specified text. Enclose a prefix term in double quotation marks ("") and add an asterisk () before the ending quotation mark, so that all text starting with the simple term specified before the asterisk is matched. The clause should be specified this way: CONTAINS (column, '"text"'). The asterisk matches zero, one, or more characters (of the root word or words in the word or phrase). If the text and asterisk are not delimited by double quotation marks, so the predicate reads CONTAINS (column, 'text*'), full-text search considers the asterisk as a character and searches for exact matches to text*. The full-text engine will not find words with the asterisk (*) character because word breakers typically ignore such characters.

When is a phrase, each word contained in the phrase is considered to be a separate prefix. Therefore, a query specifying a prefix term of "local wine*" matches any rows with the text of "local winery", "locally wined and dined", and so on.

Have a look at the MSDN on the topic. MSDN




回答2:


Have you tried to query the following view to see what's on the system stoplist?

select * from sys.fulltext_system_stopwords where language_id = 1033;



回答3:


Found a solution that works. I've added language 1033 as an additional parameter.

SELECT * FROM MyTable WHERE CONTAINS(Message, @Keyword, langauge 1033) 


来源:https://stackoverflow.com/questions/19911222/strange-behaviour-with-fulltext-search-in-sql-server

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