SQL Server 2008 データベースと全文検索を使用するアプリケーションがあります。次の検索の動作が異なる理由を理解しようとしています。
まず、次のようなハイフンでつながれた単語を含むフレーズ:
contains(column_name, '"one two-three-four five"')
2 つ目は、ハイフンがスペースに置き換えられた同一のフレーズです。
contains(column_name, '"one two three four five"')
フルテキスト インデックスは、ENGLISH (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;