简体   繁体   English

SQL Server中全文搜索的奇怪行为

[英]Strange behaviour with Fulltext search in SQL Server

I have MyTable with a Column Message NVARCHAR(MAX). 我有带有列消息NVARCHAR(MAX)的MyTable。

Record with ID 1 contains the Message '0123456789333444 Test' ID为1的记录包含消息“ 0123456789333444测试”

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. 记录ID 1显示在结果中,我认为不应,因为0123456789333444不包含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

This is because the @Keyword is not wrapped in double quotes. 这是因为@Keyword没有用双引号引起来。 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 "'). 该子句的指定方式应为:CONTAINS(列,“文本 ”)。 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*. 如果文本和星号没有用双引号引起来,则谓词为CONTAINS(列,“文本*”),则全文搜索会将星号视为字符,并搜索与文本*的完全匹配项。 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. 因此,指定前缀术语“ local wine *”的查询将与文本为“ local winery”,“ local wined and dined”等的任何行匹配。

Have a look at the MSDN on the topic. 看一下有关该主题的MSDN。 MSDN MSDN

您是否尝试过查询以下视图以查看系统停止列表上的内容?

select * from sys.fulltext_system_stopwords where language_id = 1033;

Found a solution that works. 找到了可行的解决方案。 I've added language 1033 as an additional parameter. 我添加了language 1033作为附加参数。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM