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)
相关推荐
暖和_白开水7 小时前
数据分析agent(十三_3):docker mysql容器镜像服务的异常错误
mysql·docker·容器
ttwuai9 小时前
AI 生成后台改数据后,操作日志别只记按钮:Go + MySQL 怎么验
数据库·人工智能·mysql·golang
韩楚风11 小时前
【参天引擎】一次宕机后的数据恢复,让我把 Cantian 持久化与恢复的六大机制全搞明白了
服务器·网络·数据库·分布式·mysql·架构·cantian
Mico1811 小时前
MySQL 8.0.35 mydumper/myloader 备份恢复工具使用
mysql
这个DBA有点耶15 小时前
热点行更新:秒杀场景下一条UPDATE语句的锁等待与性能优化
数据库·sql·mysql·性能优化·database·dba
冰暮流星17 小时前
mysql之新建表及对表的查询
android·数据库·mysql
Bug收容所17 小时前
12305项目学习day5
java·spring boot·redis·mysql·spring·rocketmq
会编程的土豆18 小时前
功能详解 01 · 用户注册:从表单到数据库一行
开发语言·数据库·后端·mysql·golang
溜达的大象18 小时前
Prometheus怎么监控MySQL?mysqld_exporter部署与告警教程
mysql·adb·prometheus
想你依然心痛18 小时前
【金仓数据库征文】LIKE查询优化:前缀、后缀与全文检索边界
全文检索·执行计划·金仓数据库·like查询·前缀匹配·后缀匹配·gin索引