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

SQL Anywhere 12.0.1 » SQL Anywhere 服务器 - SQL 的用法 » 查询和修改数据 » 全文搜索

 

教程:执行模糊全文搜索

可通过以下过程对使用 NGRAM 术语断开器的文本索引执行模糊全文搜索。

 ♦ 对 NGRAM 术语索引执行模糊全文搜索
  1. 启动 Interactive SQL 并使用 SQL Anywhere 12 Demo 数据源连接到示例数据库。

  2. 执行以下语句以创建名为 myFuzzyTextConfig 的文本配置对象。

    CREATE TEXT CONFIGURATION myFuzzyTextConfig FROM default_char;
  3. 执行以下语句,将术语断开器更改为 NGRAM 并将最大术语长度设置为 3。然后使用 n 元语法词执行模糊搜索。使用单独的 ALTER TEXT CONFIGURATION 语句来实现这些更改:

    ALTER TEXT CONFIGURATION myFuzzyTextConfig
       TERM BREAKER NGRAM;
    ALTER TEXT CONFIGURATION myFuzzyTextConfig
       MAXIMUM TERM LENGTH 3;
  4. 启动 Sybase Central 并使用 SQL Anywhere 12 Demo 数据源连接到示例数据库。

  5. 创建 MarketingInformation 表的副本。

    1. 在 Sybase Central 中,展开 [] 文件夹。

    2. 右击 MarketingInformation,然后单击 [复制]。

    3. 右击 [] 文件夹,然后单击 [粘贴]。

    4. 在 [名称] 字段中键入 MarketingInformation2。单击 [确定]。

  6. 在 Interactive SQL 中,执行以下语句向 MarketingInformation2 表中添加数据:

    INSERT INTO MarketingInformation2
       SELECT * FROM MarketingInformation;
  7. 执行以下语句,可在 MarketingInformation2.Description 列上创建引用 myFuzzyTextConfig 文本配置对象的文本索引:

    CREATE TEXT INDEX myFuzzyTextIdx ON MarketingInformation2 ( Description ) 
       CONFIGURATION myFuzzyTextConfig;
  8. 执行以下语句检查与 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
    注意

    最后六行具有包含匹配 n 元语法词的术语。然而,不会为其指定分数,因为表中的所有行都包含这些术语。

  9. 从 Interactive SQL 和 Sybase Central 断开连接。

  10. (可选)将示例数据库 (demo.db) 恢复至其初始状态。

 另请参见