SQL Server全文搜索包含连字符的短语不会返回预期结果
发布时间:2020-05-28 18:26:23 所属栏目:MsSql 来源:互联网
导读:我们有一个使用SQL Server 2008数据库和全文搜索的应用程序.我试图理解为什么以下搜索的行为不同: 首先,包含带连字符的短语,如下所示: contains(column_name, one two-three-four five) 第二,一个相同的短语,连字符被空格替换: contains(column_name, one
|
我们有一个使用SQL Server 2008数据库和全文搜索的应用程序.我试图理解为什么以下搜索的行为不同: 首先,包含带连字符的短语,如下所示: contains(column_name,'"one two-three-four five"') 第二,一个相同的短语,连字符被空格替换: contains(column_name,'"one two three four five"') 全文索引使用ENGLISH(1033)语言环境和默认系统停止列表. 根据我对包含带连字符的单词的其他全文搜索的观察,第一个应该允许匹配一两三四五或一二二五.相反,它只匹配一个twothreefour五(而不是一个二三四五). 测试用例 建立: create table ftTest
(
Id int identity(1,1) not null,Value nvarchar(100) not null,constraint PK_ftTest primary key (Id)
);
insert ftTest (Value) values ('one two-three-four five');
insert ftTest (Value) values ('one twothreefour five');
create fulltext catalog ftTest_catalog;
create fulltext index on ftTest (Value language 1033)
key index PK_ftTest on ftTest_catalog;
GO
查询: --returns one match select * from ftTest where contains(Value,'"one two-three-four five"') --returns two matches select * from ftTest where contains(Value,'"one two three four five"') select * from ftTest where contains(Value,'one and "two-three-four five"') select * from ftTest where contains(Value,'"one two-three-four" and five') GO 清理: drop fulltext index on ftTest drop fulltext catalog ftTest_catalog; drop table ftTest; 解决方法http://support.microsoft.com/default.aspx?scid=kb;en-us;200043“如果必须在搜索标题中使用非字母数字字符(主要是短划线’ – ‘字符),请使用Transact-SQL LIKE子句而不是FULLTEXT或CONTAINS谓词.” (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
