我们有一个使用SQL Server 2008数据库和全文搜索的应用程序。我试图理解为什么下面的搜索行为不同:SQL Server全文搜索包含连字符的短语不会返回预期结果
首先,含有连字符的单词短语,如:
contains(column_name, '"one two-three-four five"')
第二,相同的短语,其中连字符用空格代替:
contains(column_name, '"one two three four five"')
全文索引使用英语(1033)语言环境和默认系统停止列表。
从我对包含带连字符的其他全文搜索的观察,第一个应允许在one two three four five
或one twothreefour five
之间匹配。相反,它只匹配one twothreefour five
(而不是one two-three-four five
)。
测试用例
设置:
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;
的问题更多的是关于*为什么* SQL服务器表现出对匹配不同的行为。解决这个问题肯定是可行的,但对我来说,“两三四五”将返回两行是毫无意义的,但“一二三四”不会。 “一二三四”同上。这真的是预期的行为?如果是这样,为什么? – Laviak 2012-07-26 07:35:15