11

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;
4

3 に答える 3

10

http://support.microsoft.com/default.aspx?scid=kb;en-us;200043

「検索基準で英数字以外の文字(主にダッシュ'-'文字)を使用する必要がある場合は、FULLTEXTまたはCONTAINS述語の代わりにTransact-SQLLIKE句を使用してください。」

于 2012-07-25T07:38:57.230 に答える
10

このようなワード ブレーカーの動作を予測できない場合は、文字列に対して sys.dm_fts_parser を実行して、単語がどのように分割され、内部インデックスに格納されるかを把握することをお勧めします。

たとえば、'"one two-three-four five"' で sys.dm_fts_parser を実行すると、次の結果が得られます -

select * from sys.dm_fts_parser('"one two-three-four five"', 1033, NULL, 0)
--edited--
1   0   1   Exact Match one
1   0   2   Exact Match two-three-four
1   0   2   Exact Match two
1   0   3   Exact Match three
1   0   4   Exact Match four
1   0   5   Exact Match five

返された結果からわかるように、ワード ブレーカーは文字列を解析し、CONTAINS クエリを実行したときに表示される結果を説明する 6 つの形式を出力します。

于 2012-09-19T22:45:29.273 に答える
3

全文検索では、単語はスペースや句読点を含まない文字列と見なされます。英数字以外の文字が出現すると、検索中に単語が「分割」される可能性があります。SQL Server の全文検索は単語ベースのエンジンであるため、句読点は通常考慮されず、インデックスの検索時に無視されます。したがって、'CONTAINS(testing, "computer-failure")' のような CONTAINS 句は、値が "The failure to find my computer would due to cost." の行に一致します。

理由のリンクをたどってください: https://support.microsoft.com/en-us/kb/200043

于 2015-09-17T05:48:54.403 に答える