Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (日本語) » SQL Anywhere サーバ - SQL の使用法 » データのクエリと変更 » データのクエリ » 全文検索のタイプ

 

近接検索

全文検索では、単一のカラム内で互いに近接する単語を検索できる機能があります。これは「近接検索」と呼ばれます。近接検索を実行するには、2 つの単語を指定して、間に NEAR キーワードまたはチルダ (~) を挿入します。

NEAR キーワードを使用して、整数引数を指定し、最大距離を指定できます。たとえば、term1 NEAR[5] term2term2 から 5 語以内に出現する term1 のインスタンスを検索します。単語の順序に意味はなく、'term1 NEAR term2''term2 NEAR term1' と同義です。

距離を指定しない場合、データベース・サーバはデフォルトの距離として 10 を使用します。

NEAR キーワードの代わりに、チルダ (~) を指定することもできます。たとえば 'term1 ~ term2' のようになります。ただし、チルダ形式を使用する場合は距離を指定できず、デフォルトの 10 が適用されます。

近接検索の引数としてフレーズを指定することはできません。

近接検索でプレフィクス単語を引数として指定すると、近接検索は AND 式に変換されます。たとえば、3-gram のテキスト・インデックスの場合、'red NEAR[1] appl*' を検索することは、'red AND "app ppl"' を検索することと同義になります。これは近接検索ではなくなったため、CONTAINS 句で複数のカラムが指定されている場合に、検索が 1 つのカラムに制限されることはありません。

MarketingInformation テーブルの Description カラムで、単語 skin から 10 語以内の距離にある単語 fabric を検索するとします。この場合、次の文を実行できます。

SELECT ID, "contains".score, Description  
   FROM MarketingInformation CONTAINS ( Description, 'fabric ~ skin' );
ID score Description
902 1.5572371866083279 <html><head><meta http-equiv=Content-Type content="text/html; charset=windows-1252"><title>Tee Shirt</title></head><body lang=EN-US><p><span style='font-size:10.0pt;font-family:Arial'>This simple, sleek, and lightweight technical shirt is designed for high-intensity workouts in hot and humid weather. The recycled polyester 「fabric」 is gentle on the earth and soft against your 「skin」.</span></p></body></html>

デフォルトの距離が 10 語なので、距離を指定する必要はありませんでした。しかし、距離を 1 語拡張することで、次のような別のローが返されます。

SELECT ID, "contains".score, Description 
   FROM MarketingInformation CONTAINS ( Description, 'fabric NEAR[11] skin' );
ID score Description
903 1.5787803210404958 <html><head><meta http-equiv=Content-Type content="text/html; charset=windows-1252"><title>Tee Shirt</title></head><body lang=EN-US><p><span style='font-size:10.0pt;font-family:Arial'>A sporty, casual shirt made of recycled water bottles. It will serve you equally well on trails or around town. The 「fabric」 has a wicking finish to pull perspiration away from your 「skin」.</span></p></body></html>
902 2.163125855043747 <html><head><meta http-equiv=Content-Type content="text/html; charset=windows-1252"><title>Tee Shirt</title></head><body lang=EN-US><p><span style='font-size:10.0pt;font-family:Arial'>This simple, sleek, and lightweight technical shirt is designed for high-intensity workouts in hot and humid weather. The recycled polyester 「fabric」 is gentle on the earth and soft against your 「skin」.</span></p></body></html>

単語間の距離が近いため、ID 903 のスコアの方が高くなります。