在SQL Server中使用全文搜索进行奇怪的行为 [英] Strange behaviour with Fulltext search in SQL Server

查看:130
本文介绍了在SQL Server中使用全文搜索进行奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的MyTable中有列消息NVARCHAR(MAX)。



ID为1的记录包含消息'0123456789333444 Test'



运行以下查询时:

  DECLARE @Keyword NVARCHAR(100)

SET @Keyword ='0123456789000001 *'

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

记录ID 1显示在结果中,我认为它不应该是因为0123456789333444不包含0123456789000001。



有人可以解释为什么记录显示出来吗?

编辑

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

返回以下内容:

  group_id phrase_id出现special_term display_term expansion_type source_term 
1 0 1完全匹配0123456789333444 0 0123456789333444测试
1 0 1完全匹配nn0123456789333444 0 0123456789333444测试
1 0 2完全匹配测试0 0123456789333444测试


解决方案

找到了可行的解决方案。

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


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

解决方案

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

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

这篇关于在SQL Server中使用全文搜索进行奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆