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 元语法执行模糊搜索。

    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。单击 [确定]。

  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
    注释

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

  12. 关闭 Interactive SQL 和 Sybase Central。

结果

已执行模糊全文搜索。

下一个

(可选)将示例数据库 (demo.db) 恢复至其原始状态。请参见重新创建示例数据库 (demo.db)

 另请参见