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 的用法 » 查询和修改数据 » 查询数据 » 全文搜索的类型

 

教程:执行模糊全文搜索

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

另请参见: 教程:对 GENERIC 文本索引执行全文搜索.

♦  对 NGRAM 术语索引执行模糊全文搜索
  1. 执行以下语句以创建名为 myFuzzyTextConfig 的文本配置对象。

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

    ALTER TEXT CONFIGURATION myFuzzyTextConfig
       TERM BREAKER NGRAM;
    ALTER TEXT CONFIGURATION myFuzzyTextConfig
       MAXIMUM TERM LENGTH 3;
  3. 创建 MarketingInformation 表的副本。

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

    2. 右击 MarketingInformation 并选择 [复制]。

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

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

  4. 执行以下命令以向 MarketingInformation2 表中添加数据:

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

    CREATE TEXT INDEX myFuzzyTextIdx ON MarketingInformation2 ( Description ) 
       CONFIGURATION myFuzzyTextConfig;
  6. 执行以下语句来测试文本索引。

    以下模糊查询将检查是否存在与 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 元语法词的术语。然而,不会为其指定分数,因为表中的所有行都包含这些术语。

另请参见