我们有使用SQL Server 2008数据库的应用程序,和全文搜索。 我试图理解为什么下面的搜索行为不同:
首先,含有连字符的单词,像这样的一句话:
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;