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

SQL Anywhere 11.0.1 (Deutsch) » SQL Anywhere Server - SQL-Benutzerhandbuch » Daten abfragen und ändern » Daten abfragen » Arten der Volltextsuche

 

Praktische Einführung: Eine Volltextsuche in einem NGRAM-Textindex durchführen

Verwenden Sie das folgende Verfahren, um eine Volltextsuche in einem Textindex auszuführen, der einen NGRAM-Begriffsegmentierer verwendet. Dieses Verfahren kann auch verwendet werden, um eine Volltextsuche von chinesischen, japanischen oder koreanischen Daten zu erstellen.

In Datenbanken mit Mehrbyte-Zeichensätzen werden möglicherweise einige Satzzeichen und Leerzeichen wie Kommas und Leerstellen mit voller Breite als alphanumerische Zeichen behandelt.

Siehe auch: Praktische Einführung: Eine Fuzzy-Volltextsuche durchführen.

♦  Volltextsuche in einem NGRAM-Textindex durchführen
  1. Führen Sie die folgende Anweisung aus, um ein NCHAR-Textkonfigurationsobjekt namens "myNcharNGRAMTextConfig" zu erstellen.

    CREATE TEXT CONFIGURATION myNcharNGRAMTextConfig FROM default_nchar;
  2. Führen Sie die folgende Anweisung aus, um den TERM BREAKER-Algorithmus auf NGRAM zu ändern und MAXIMUM TERM LENGTH (N) auf 2 zu setzen.

    ALTER TEXT CONFIGURATION myNcharNGRAMTextConfig 
       TERM BREAKER NGRAM;
    ALTER TEXT CONFIGURATION myNcharNGRAMTextConfig 
       MAXIMUM TERM LENGTH 2;

    Bei chinesischen, japanischen und koreanischen Daten ist der empfohlene Wert für N 2 oder 3. Bei Suchen, die auf ein oder zwei Zeichen beschränkt sind, setzen Sie den N-Wert auf 1. Das Festlegen des N-Werts auf 1 kann eine langsamere Ausführung von langen Abfragen bewirken.

  3. Erstellen Sie eine Kopie der MarketingInformation-Tabelle.

    1. In Sybase Central erweitern Sie den Ordner Tabellen.

    2. Rechtsklicken Sie auf MarketingInformation und wählen Sie Kopieren.

    3. Rechtsklicken Sie auf den Ordner Tabellen und wählen Sie Einfügen.

    4. Im Feld Name geben Sie MarketingInformationNgram ein. Klicken Sie auf OK.

  4. Führen Sie die folgende Anweisung aus, um der Tabelle "MarketingInformationNgram" Daten hinzuzufügen:

    INSERT INTO MarketingInformationNgram
       SELECT *
          FROM MarketingInformation;
    COMMIT;
    
  5. Führen Sie die folgende Anweisung aus, um einen IMMEDIATE REFRESH-Textindex für die Spalte "MarketingInformationNgram.Description" unter Verwendung des Textkonfigurationsobjekts "myNcharNGRAMTextConfig" zu erstellen:

    CREATE TEXT INDEX ncharNGRAMTextIndex 
       ON MarketingInformationNgram( Description ) 
          CONFIGURATION myNcharNGRAMTextConfig;
    
  6. Führen Sie die folgenden Anweisungen aus, um den Textindex zu testen:

    1. Diese Anweisung durchsucht den 2-gram-Textindex nach Begriffen, die sw enthalten. Die Ergebnisse werden anhand der Punktewerte in absteigender Sortierfolge sortiert.

      SELECT M.Description, ct.*
         FROM MarketingInformationNgram AS M 
      CONTAINS( M.Description, 'sw' ) 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> 2,262071918398649
      <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> 1,5556043490424176
    2. Die folgende Anweisung sucht nach Begriffen, die ams enthalten. Die Ergebnisse werden anhand der Punktewerte in absteigender Sortierfolge sortiert.

      SELECT M.Description, ct.*
         FROM MarketingInformationNgram AS M 
      CONTAINS( M.Description, 'ams' ) ct
         ORDER BY ct.score DESC;
      

      Beim 2-gram-Textindex ist die vorherige Anweisung äquivalent zu:

      SELECT M.Description, ct.*
         FROM MarketingInformationNgram AS M 
      CONTAINS( M.Description, '"am ms"' ) 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> 1,6619019465461564
      <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> 1,5556043490424176
    3. Die folgende Anweisung sucht nach Begriffen mit v gefolgt von einem beliebigen alphanumerischen Zeichen. Da ve in den indizierten Daten häufiger vorkommt, erhalten Zeilen, die das 2-gram ve enthalten, eine niedrigere Bewertung als Zeilen, die vi enthalten. Die Ergebnisse werden anhand der Punktewerte in absteigender Sortierfolge sortiert.

      SELECT M.ID, M.Description, ct.*
         FROM MarketingInformationNgram AS M 
      CONTAINS( M.Description, 'v*' ) ct
         ORDER BY ct.score DESC;
      
      ID Description Score
      901 <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 favvorite. A sleek and technical shirt built for the trail, track, or sidewalk. UPF rating of 50+.</span></p></body></html> 3,3416789108071976
      907 <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> 2,1123084896159376
      905 <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> 1,6750365447462499
      910 <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
      906 <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
      904 <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,7313071661212746
      903 <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,6799436746197272
    4. Die folgenden Anweisungen durchsuchen jede Zeile nach Begriffen, die "v" enthalten. Nach der zweiten Anweisung enthält die Variable die Zeichenfolge av OR ev OR iv OR ov OR rv OR ve OR vi OR vo. Die Ergebnisse werden anhand der Punktewerte in absteigender Sortierfolge sortiert. Wenn ein N-Gramm in allen indizierten Zeilen vorkommt, wird ihm ein Punktewert von null zugewiesen.

      Dies ist die einzige Methode, die es ermöglicht, ein einzelnes Zeichen aufzufinden, wenn es vor einer Leerstelle oder einem nicht-alphanumerischen Zeichen auftritt.

      CREATE VARIABLE query NVARCHAR (100);
      SELECT LIST (term, ' OR ' )
      INTO query
         FROM sa_text_index_vocab( 'ncharNGRAMTextIndex', 'MarketingInformationNgram', 'dba' )
         WHERE term LIKE '%v%';
      SELECT M.ID, M.Description, ct.*
         FROM MarketingInformationNgram AS M 
         CONTAINS( M.Description, query ) ct
         ORDER BY ct.score DESC;
      
      ID Description Score
      901 <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> 6,654350268810443
      907 <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> 4,265623837817126
      903 <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> 2,9386676702799504
      910 <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> 2,5481193655722336
      904 <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> 2,4293498211307214
      905 <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> 1,6750365447462499
      906 <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
      902 <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
      908 <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
      909 <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
    5. Die folgende Anweisung durchsucht die Spalte Description nach Zeilen, die ea, ka und k enthalten.

      SELECT M.ID, M.Description, ct.*
         FROM MarketingInformationNgram AS M 
      CONTAINS( M.Description, 'ea ka ki' ) ct
        ORDER BY ct.score DESC;
      
      ID Description Score
      904 <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> 3,4151032739119733
    6. Die folgende Anweisung durchsucht die Spalte "Description" nach Zeilen, die ve und vi, aber nicht gg enthalten.

      SELECT M.ID, M.Description, ct.*
         FROM MarketingInformationNgram AS M 
      CONTAINS( M.Description, 've & vi –gg' ) ct
         ORDER BY ct.score DESC;
      
      ID Description Score
      905 <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> 1,6750365447462499