我们有一个使用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谓词.”