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

SAP Sybase SQL Anywhere 16.0 » SQL Anywhere サーバ SQL の使用法 » クエリとデータ修正 » 全文検索

 

チュートリアル:あいまい全文検索の実行

NGRAM 単語区切りを使用するテキストインデックスに対して、あいまい全文検索を実行します。

前提条件

CREATE TEXT CONFIGURATION と CREATE TABLE のシステム権限が必要です。さらに、SELECT ANY TABLE システム権限、または、テーブル MarketingInformation に対する SELECT 権限も必要です。

 ♦ タスク
  1. Interactive SQL を起動します。[スタート] » [プログラム] » [SQL Anywhere 16] » [管理ツール] » [Interactive SQL] をクリックします。

  2. [接続] ウィンドウで、次のフィールドに入力します。

    1. [認証] ドロップダウンリストで [データベース] をクリックします。

    2. [ユーザ ID] フィールドに、DBA と入力します。

    3. [パスワード] フィールドに、sql と入力します。

    4. [アクション] ドロップダウンリストで、[ODBC データソースを使用した接続] を選択します。

  3. 次の文を実行して、myFuzzyTextConfig というテキスト設定オブジェクトを作成します。FROM 句を含めて、テンプレートとして使用するテキスト設定オブジェクトを指定する必要があります。

    CREATE TEXT CONFIGURATION myFuzzyTextConfig FROM default_char;
  4. 次の文を実行して、単語区切りを NGRAM に変更し、単語の最大長を 3 に設定します。あいまい検索は N-gram を使用して実行されます。

    ALTER TEXT CONFIGURATION myFuzzyTextConfig
       TERM BREAKER NGRAM;
    ALTER TEXT CONFIGURATION myFuzzyTextConfig
       MAXIMUM TERM LENGTH 3;
  5. Sybase Central を起動します。[スタート] » [プログラム] » [SQL Anywhere 16] » [管理ツール] » [Sybase Central] をクリックします。

  6. [接続] » [SQL Anywhere 16 に接続] をクリックします。

  7. [接続] ウィンドウで、次のフィールドに入力します。

    1. [認証] ドロップダウンリストで [データベース] をクリックします。

    2. [ユーザ ID] フィールドに、DBA と入力します。

    3. [パスワード] フィールドに、sql と入力します。

    4. [アクション] ドロップダウンリストで、[ODBC データソースを使用した接続] を選択します。

  8. MarketingInformation テーブルのコピーを作成します。

    1. Sybase Central で [テーブル] フォルダを拡張します。

    2. [MarketingInformation] を右クリックし、[コピー] をクリックします。

    3. [テーブル] フォルダを右クリックし、[貼り付け] をクリックします。

    4. [名前] フィールドに MarketingInformation2 と入力します。[OK] をクリックします。

  9. Interactive SQL で、次の文を実行して、MarketingInformation2 テーブルにデータを追加します。

    INSERT INTO MarketingInformation2
       SELECT * FROM GROUPO.MarketingInformation;
  10. 次の文を実行して、MarketingInformation2 テーブルの Description カラムに、myFuzzyTextConfig テキスト設定オブジェクトを参照するテキストインデックスを作成します。

    CREATE TEXT INDEX myFuzzyTextIdx ON MarketingInformation2 ( Description ) 
       CONFIGURATION myFuzzyTextConfig;
  11. 次の文を実行して、coten に似た単語を検索します。

    SELECT MarketingInformation2.Description, ct.* 
        FROM MarketingInformation2 CONTAINS ( MarketingInformation2.Description, 'FUZZY "coten"' ) ct 
        ORDER BY ct.score DESC;
    Description Score
    <html><head><meta http-equiv=「Content」-Type 「content」="text/html; charset=windows-1252"><title>Sweatshirt</title></head><body lang=EN-US><p><span style='font-size:10.0pt;font-family:Arial'>Lightweight 100% organically grown 「cotton」 hooded sweatshirt with taped neck seams. Comes pre-washed for softness and to lessen shrinkage.</span></p></body></html> 0.9461597363521859
    <html><head><meta http-equiv=「Content」-Type 「content」="text/html; charset=windows-1252"><title>Shorts</title></head><body lang=EN-US><p><span style='font-size:10.0pt;font-family:Arial'>These quick-drying 「cotton」 shorts provide all day comfort on or off the trails. Now with a more comfortable and stretchy fabric and an adjustable drawstring waist.</span></p></body></html> 0.9244136988525732
    <html><head><meta http-equiv=「Content」-Type 「content」="text/html; charset=windows-1252"><title>Visor</title></head><body lang=EN-US><p><span style='font-size:10.0pt;font-family:Arial'>Lightweight 100% organically grown 「cotton」 construction. Shields against sun and precipitation. Metallic ions in the fibers inhibit bacterial growth, and help neutralize odor.</span></p></body></html> 0.9134171046194403
    <html><head><meta http-equiv=「Content」-Type 「content」="text/html; charset=windows-1252"><title>Sweatshirt</title></head><body lang=EN-US><p><span style='font-size:10.0pt;font-family:Arial'>Top-notch construction includes durable topstitched seams for strength with low-bulk, resilient rib-knit collar, cuffs and bottom. An 80% 「cotton」/20% polyester blend makes it easy to keep them clean.</span></p></body></html> 0.8856420222728282
    <html><head><meta http-equiv=「Content」-Type 「content」="text/html; charset=windows-1252"><title>Baseball Cap</title></head><body lang=EN-US><p><span style='font-size:10.0pt;font-family:Arial'>This fashionable hat is ideal for glacier travel, sea-kayaking, and hiking. With concealed draw cord for windy days.</span></p></body></html> 0
    <html><head><meta http-equiv=「Content」-Type 「content」="text/html; charset=windows-1252"><title>Baseball Cap</title></head><body lang=EN-US><p><span style='font-size:10.0pt;font-family:Arial'>A lightweight wool cap with mesh side vents for breathable comfort during aerobic activities. Moisture-absorbing headband liner.</span></p></body></html> 0
    <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'>We've improved the design of this perennial favorite. A sleek and technical shirt built for the trail, track, or sidewalk. UPF rating of 50+.</span></p></body></html> 0
    <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> 0
    <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> 0
    <html><head><meta http-equiv=「Content」-Type 「content」="text/html; charset=windows-1252"><title>Visor</title></head><body lang=EN-US><p><span style='font-size:10.0pt;font-family:Arial'>A polycarbonate visor with an abrasion-resistant coating on the outside. Great for jogging in the spring, summer, and early fall. The elastic headband has plenty of stretch to give you a snug yet comfortable fit every time you wear it.</span></p></body></html> 0
    注意

    最後の 6 つのローに、一致する N-gram を含む単語があります。ただし、これらの単語はテーブル内のすべてのローに含まれているため、スコアは割り当てられていません。

  12. Interactive SQL と Sybase Central を閉じます。

結果

あいまい全文検索が実行されました。

次の手順

(省略可) サンプルデータベース (demo.db) を元の状態にリストアします。サンプルデータベースの再作成 (demo.db)を参照してください。

 参照