我们有一个使用 SQL Server 2008 数据库和全文搜索的应用程序。我试图理解为什么以下搜索的行为不同:
首先,一个包含连字符的单词的短语,如下所示:
contains(column_name, '"one two-three-four five"')
其次,是一个相同的短语,其中连字符被空格替换:
contains(column_name, '"one two three four five"')
全文索引使用 ENGLISH (1033) 区域设置和默认系统非索引字表。
根据我对包含连字符的其他全文搜索的观察,第一个应该允许匹配one two three four five
or one twothreefour five
。相反,它只匹配one twothreefour five
(并不是one two-three-four five
).
测试用例
Setup:
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
Queries:
--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
Cleanup:
drop fulltext index on ftTest
drop fulltext catalog ftTest_catalog;
drop table ftTest;