MySQL 全文检索

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: 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)
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
6天前
|
存储 SQL 关系型数据库
【MySQL】14. 全文索引(选学)
【MySQL】14. 全文索引(选学)
12 0
|
存储 自然语言处理 关系型数据库
mysql/mariadb 实现全文检索
mysql/mariadb 实现全文检索
mysql/mariadb 实现全文检索
|
10月前
|
存储 SQL 缓存
Mysql常用三大引擎
Mysql常用三大引擎
110 0
|
11月前
|
SQL 自然语言处理 搜索推荐
mysql全文搜索
mysql全文搜索
76 2
|
12月前
|
存储 算法 关系型数据库
MySQL - MySQL不同存储引擎下索引的实现
MySQL - MySQL不同存储引擎下索引的实现
52 0
|
存储 关系型数据库 MySQL
【MySQL高级】MySQL的存储引擎
【MySQL高级】MySQL的存储引擎
65 0
【MySQL高级】MySQL的存储引擎
|
SQL 关系型数据库 MySQL
MYSQL中LIKE(模糊查询)
通常我们在搜索的时候总是不会特别精准,例如在百度上搜索,主要搜索关键字,然后加载页面之后再挑选。所以,在数据库中,有时候会将查询条件不一定直接使用uuid这样的标准查询。实际业务中可能存在模糊查询的业务。所以,我们可以使用LIKE关键字模糊查询符合要求的结果集,模糊查询在实际业务中主要用于搜索关键字查询需要的信息。
212 0
MYSQL中LIKE(模糊查询)
|
SQL 分布式计算 关系型数据库
初识MySQL之数据查询篇(上)
初识MySQL之数据查询篇(上)
112 0
初识MySQL之数据查询篇(上)
|
存储 Oracle 关系型数据库
初识MySQL之数据查询篇(下)
初识MySQL之数据查询篇(下)
142 0
初识MySQL之数据查询篇(下)
|
存储 缓存 安全
MySQL高级篇——聊聊MySQL的存储引擎
MySQL高级篇——聊聊MySQL的存储引擎
MySQL高级篇——聊聊MySQL的存储引擎