MySQL 全文检索

不是所有的数据表都支持全文检索 MySQL支持多种底层数据库引擎,但是并非所有的引擎支持全文检索 ,目前最常用引擎是是MyISAM和InnoDB;前者支持全文检索,后者不支持。

booolean模式操作符

操作符含义
+必须有
-必须不包含
>包含对应关键字的排名靠前
<包含对应关键字的排名靠后
~取反()
*放在词尾 类似通配符
" "引号中间作为一个完整的值处理

实验: 

表productnotes :

1.查询包含rabbit的行,并按照相关性排序

mysql> SELECT note_text
    -> FROM productnotes
    -> WHERE Match(note_text) Against('rabbit');
+----------------------------------------------------------------------------------------------------------------------+
| note_text                                                                                                            |
+----------------------------------------------------------------------------------------------------------------------+
| Customer complaint: rabbit has been able to detect trap, food apparently less effective now.                         |
| 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.01 sec)

 2.显示每一条的相关性值

mysql> SELECT note_text,
    ->  Match(note_text) Against('rabbit') AS match_rank
    -> FROM productnotes;
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------+
| note_text                                                                                                                                                 | match_rank         |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------+
| Customer complaint:
Sticks not individually wrapped, too easy to mistakenly detonate all at once.
Recommend individual wrapping.                          |                  0 |
| Can shipped full, refills not available.
Need to order new can if refill needed.                                                                          |                  0 |
| Safe is combination locked, combination not provided with safe.
This is rarely a problem as safes are typically blown up or dropped by customers.         |                  0 |
| Quantity varies, sold by the sack load.
All guaranteed to be bright and orange, and suitable for use as rabbit bait.                                      | 1.5905543565750122 |
| 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. |                  0 |
| Matches not included, recommend purchase of matches or detonator (item DTNTR).                                                                            |                  0 |
| Please note that no returns will be accepted if safe opened using explosives.                                                                             |                  0 |
| Multiple customer returns, anvils failing to drop fast enough or falling backwards on purchaser. Recommend that customer considers using heavier anvils.  |                  0 |
| Item is extremely heavy. Designed for dropping, not recommended for use with slings, ropes, pulleys, or tightropes.                                       |                  0 |
| Customer complaint: rabbit has been able to detect trap, food apparently less effective now.                                                              | 1.6408053636550903 |
| Shipped unassembled, requires common tools (including oversized hammer).                                                                                  |                  0 |
| Customer complaint:
Circular hole in safe floor can apparently be easily cut with handsaw.                                                                |                  0 |
| Customer complaint:
Not heavy enough to generate flying stars around head of victim. If being purchased for dropping, recommend ANV02 or ANV03 instead.   |                  0 |
| Call from individual trapped in safe plummeting to the ground, suggests an escape hatch be added.
Comment forwarded to vendor.                            |                  0 |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------+
14 rows in set (0.00 sec)

3.有heavy 但是没有rope

mysql> SELECT note_text
    -> FROM productnotes
    -> WHERE Match(note_text)
    ->  Against('heavy -rope*' IN BOOLEAN MODE);
+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| 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)

  • 10
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MySQL全文检索是一种用于在文本数据中进行高效搜索的技术。在MySQL中,全文索引相关参数无法进行动态修改,只能通过修改配置文件来完成。你可以通过修改my.ini配置文件中的相关参数来调整全文检索的配置。比如,你可以通过设置innodb_ft_min_token_size和ft_min_word_len参数来修改最小搜索长度为1的配置。 在使用全文检索进行查询时,你需要使用match和against关键字。match中的列必须要与设置全文索引的列对应,而against中填写的是你要查询的内容。例如,你可以使用以下代码进行全文检索查询: SELECT * FROM emp WHERE MATCH(empName,empPass,empPhone) AGAINST('a'); 需要注意的是,全文检索主要应用于搜索引擎和大数据搜索等领域。在一般的数据库中,如小规模的数据库,通常不需要使用全文检索,普通的查询就能满足大部分需求。 使用MySQL进行全文检索的步骤如下: 1. 建立数据表。 2. 创建全文索引。可以使用ALTER TABLE语句来为表添加全文索引。 3. 进行全文检索查询。使用match和against关键字指定要查询的列和查询内容,执行相应的SQL语句即可。 在进行全文检索时,你还可以使用一些修饰符来自定义检索体的相关性,例如必须包含该词、必须不包含该词、提高词的相关性等。MySQL中常用的修饰符有必须包含该词(+)、必须不包含该词(-)、提高词的相关性(>)、降低词的相关性(<)和通配符(*)。更多解释可以参考相关资料进行学习。 综上所述,MySQL全文检索是一种用于在文本数据中进行高效搜索的技术,可以通过修改配置文件来调整相关参数,使用match和against关键字来进行查询,适用于搜索引擎和大数据搜索等场景。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值