zoukankan      html  css  js  c++  java
  • MariaDB Full-Text Searching

    MariaDB Full-Text Searching




    CREATE TABLE productnotes

    (

      note_id    int           NOT NULL AUTO_INCREMENT,

      prod_id    char(10)      NOT NULL,

      note_date datetime       NOT NULL,

      note_text  text          NULL ,

      PRIMARY KEY(note_id),

      FULLTEXT(note_text)

    ) ENGINE=Aria;


    Full-Text Searching不是所有存储引擎都支持,这里选择最新的Aria引擎,可以在创建表的时候通过FULLTEXT()来启用FULLTEXT Searching,也可以通过ALTER来修改



    (jlive)[crashcourse]>SELECT note_text FROM productnotes WHERE Match(note_text) Against('rabbit')G

    *************************** 1. row ***************************

    note_text: Customer complaint: rabbit has been able to detect trap, food apparently less effective now.

    *************************** 2. row ***************************

    note_text: Quantity varies, sold by the sack load.

    All guaranteed to be bright and orange, and suitable for use as rabbit bait.

    2 rows in set (0.00 sec)


    (jlive)[crashcourse]>SELECT note_text FROM productnotes WHERE note_text LIKE '%rabbit%'G

    *************************** 1. row ***************************

    note_text: Quantity varies, sold by the sack load.

    All guaranteed to be bright and orange, and suitable for use as rabbit bait.

    *************************** 2. row ***************************

    note_text: Customer complaint: rabbit has been able to detect trap, food apparently less effective now.


    2 rows in set (0.00 sec)

     

    支持通配





    (jlive)[crashcourse]>SELECT note_text, Match(note_text) Against('rabbit') AS rank FROM productnotesG

    *************************** 1. row ***************************

    note_text: Customer complaint:

    Sticks not individually wrapped, too easy to mistakenly detonate all at once.

    Recommend individual wrapping.

         rank: 0

    *************************** 2. row ***************************

    note_text: Can shipped full, refills not available.

    Need to order new can if refill needed.

         rank: 0

    *************************** 3. row ***************************

    note_text: Safe is combination locked, combination not provided with safe.

    This is rarely a problem as safes are typically blown up or dropped by customers.

         rank: 0

    *************************** 4. row ***************************

    note_text: Quantity varies, sold by the sack load.

    All guaranteed to be bright and orange, and suitable for use as rabbit bait.

         rank: 1.5905543565750122

    *************************** 5. row ***************************

    note_text: Included fuses are short and have been known to detonate too quickly for some customers.

    Longer fuses are available (item FU1) and should be recommended.

         rank: 0

    *************************** 6. row ***************************

    note_text: Matches not included, recommend purchase of matches or detonator (item DTNTR).

         rank: 0

    *************************** 7. row ***************************

    note_text: Please note that no returns will be accepted if safe opened using explosives.

         rank: 0

    *************************** 8. row ***************************

    note_text: Multiple customer returns, anvils failing to drop fast enough or falling backwards on purchaser. Recommend that customer considers using heavier anvils.

         rank: 0

    *************************** 9. row ***************************

    note_text: Item is extremely heavy. Designed for dropping, not recommended for use with slings, ropes, pulleys, or tightropes.

         rank: 0

    *************************** 10. row ***************************

    note_text: Customer complaint: rabbit has been able to detect trap, food apparently less effective now.

         rank: 1.6408053636550903

    *************************** 11. row ***************************

    note_text: Shipped unassembled, requires common tools (including oversized hammer).

         rank: 0

    *************************** 12. row ***************************

    note_text: Customer complaint:

    Circular hole in safe floor can apparently be easily cut with handsaw.

         rank: 0

    *************************** 13. row ***************************

    note_text: Customer complaint:

    Not heavy enough to generate flying stars around head of victim. If being purchased for dropping, recommend ANV02 or ANV03 instead.

         rank: 0

    *************************** 14. row ***************************

    note_text: Call from individual trapped in safe plummeting to the ground, suggests an escape hatch be added.

    Comment forwarded to vendor.

         rank: 0


    14 rows in set (0.00 sec)

    rankFullText Search所用的时间


     


    WITH QUERY EXPANSION

    1.根据匹配关键词进行匹配,查询出所以匹配的行

    2.以前面匹配的行为基准,进行拆分匹配,越接近的越排名靠前

    3.显示12两步的结果

    (jlive)[crashcourse]>SELECT note_text FROM productnotes WHERE Match(note_text) Against('anvils')G

    *************************** 1. row ***************************

    note_text: Multiple customer returns, anvils failing to drop fast enough or falling backwards on purchaser. Recommend that customer considers using heavier anvils.

     

    1 row in set (0.00 sec)

    (jlive)[crashcourse]>SELECT note_text FROM productnotes WHERE Match(note_text) Against('anvils' WITH QUERY EXPANSION)G

    *************************** 1. row ***************************

    note_text: Multiple customer returns, anvils failing to drop fast enough or falling backwards on purchaser. Recommend that customer considers using heavier anvils.

    *************************** 2. row ***************************

    note_text: Customer complaint:

    Sticks not individually wrapped, too easy to mistakenly detonate all at once.

    Recommend individual wrapping.

    *************************** 3. row ***************************

    note_text: Customer complaint:

    Not heavy enough to generate flying stars around head of victim. If being purchased for dropping, recommend ANV02 or ANV03 instead.

    *************************** 4. row ***************************

    note_text: Please note that no returns will be accepted if safe opened using explosives.

    *************************** 5. row ***************************

    note_text: Customer complaint: rabbit has been able to detect trap, food apparently less effective now.

    *************************** 6. row ***************************

    note_text: Customer complaint:

    Circular hole in safe floor can apparently be easily cut with handsaw.

    *************************** 7. row ***************************

    note_text: Matches not included, recommend purchase of matches or detonator (item DTNTR).

    7 rows in set (0.00 sec)


     

    The More Rows the Better The more rows in your table (and the more text within those rows), the better the results returned when using query expansion.



    Boolean Text Searches

    MariaDB <wbr>Full-Text <wbr>Searching

    (jlive)[crashcourse]>SELECT note_text FROM productnotes WHERE Match(note_text) Against('heavy' IN BOOLEAN MODE)G

    *************************** 1. row ***************************

    note_text: Item is extremely heavy. Designed for dropping, not recommended for use with slings, ropes, pulleys, or tightropes.

    *************************** 2. row ***************************

    note_text: Customer complaint:

    Not heavy enough to generate flying stars around head of victim. If being purchased for dropping, recommend ANV02 or ANV03 instead.

    2 rows in set (0.00 sec)


    (jlive)[crashcourse]>SELECT note_text FROM productnotes WHERE Match(note_text) Against('heavy -rope*' IN BOOLEAN MODE)G

    *************************** 1. row ***************************

    note_text: Customer complaint:

    Not heavy enough to generate flying stars around head of victim. If being purchased for dropping, recommend ANV02 or ANV03 instead.

    1 row in set (0.00 sec) 



    (jlive)[crashcourse]>SELECT note_text FROM productnotes WHERE Match(note_text) Against('+rabbit +bait' IN BOOLEAN MODE)G

    *************************** 1. row ***************************

    note_text: Quantity varies, sold by the sack load.

    All guaranteed to be bright and orange, and suitable for use as rabbit bait.

    1 row in set (0.00 sec)

    rabbit,bait必须存在


    (jlive)[crashcourse]>SELECT note_text FROM productnotes WHERE Match(note_text) Against('rabbit bait' IN BOOLEAN MODE)G

    *************************** 1. row ***************************

    note_text: Quantity varies, sold by the sack load.

    All guaranteed to be bright and orange, and suitable for use as rabbit bait.

    *************************** 2. row ***************************

    note_text: Customer complaint: rabbit has been able to detect trap, food apparently less effective now.


    2 rows in set (0.00 sec)

    rabbit,bait至少有一个存在即可



    (jlive)[crashcourse]>SELECT note_text FROM productnotes WHERE Match(note_text) Against('>rabbit IN BOOLEAN MODE)G

    *************************** 1. row ***************************

    note_text: Quantity varies, sold by the sack load.

    All guaranteed to be bright and orange, and suitable for use as rabbit bait.

    *************************** 2. row ***************************

    note_text: Customer complaint: rabbit has been able to detect trap, food apparently less effective now.


    2 rows in set (0.00 sec)

    rabbit存在的行放在carrot存在行的前面


    (jlive)[crashcourse]>SELECT note_text FROM productnotes WHERE Match(note_text) Against('+safe +(' IN BOOLEAN MODE)G

    *************************** 1. row ***************************

    note_text: Safe is combination locked, combination not provided with safe.

    This is rarely a problem as safes are typically blown up or dropped by customers.


    1 row in set (0.00 sec)

     

    safe,combination都必须存在,并且包含combination的行尽量往前排

  • 相关阅读:
    Eclipse 修改编码方式
    mybits like查询写法
    Cannot convert value '0000-00-00 00:00:00' TIMESTAMP
    Homebrew简介和基本使用
    linux命令学习之:vim
    log4j配置详解
    log4j日志配置(按天/按日)
    Linux下tar.gz、tar、bz2、zip等解压缩、压缩命令小结(转)
    Linux挂载磁盘
    linux命令学习之:echo
  • 原文地址:https://www.cnblogs.com/lixuebin/p/10814178.html
Copyright © 2011-2022 走看看