MySQL全文检索的实现示例

 更新时间:2024年04月18日 08:41:06   作者:Q小白养成记  
全文搜索是一种在文本字段中查找关键词的功能。在MySQL中,我们可以使用全文搜索来提高查询的效率,本文主要介绍了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)

到此这篇关于MySQL 全文检索的文章就介绍到这了,更多相关MySQL 全文检索内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家! 

相关文章

  • Mysql将查询结果集转换为JSON数据的实例代码

    Mysql将查询结果集转换为JSON数据的实例代码

    这篇文章主要介绍了Mysql将查询结果集转换为JSON数据的实例代码,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-03-03
  • mysql IS NULL使用索引案例讲解

    mysql IS NULL使用索引案例讲解

    这篇文章主要介绍了mysql IS NULL使用索引案例讲解,本篇文章通过简要的案例,讲解了该项技术的了解与使用,以下就是详细内容,需要的朋友可以参考下
    2021-08-08
  • MySQL百万数据深度分页优化思路解析

    MySQL百万数据深度分页优化思路解析

    这篇文章主要为大家介绍了MySQL百万数据深度分页优化思路分析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-05-05
  • mysql中数据库与数据表编码格式的查看、创建及修改

    mysql中数据库与数据表编码格式的查看、创建及修改

    这篇文章给大家介绍了如何查看、创建以及修改数据库与数据表的编码格式,另外还给大家分享了添加和删除外键的示例代码,文中介绍的很详细,对大家的理解和学习具有一定的参考借鉴价值,有需要的朋友们下面来一起学习学习吧。
    2016-11-11
  • 详解MySQL查看执行慢的SQL语句(慢查询)

    详解MySQL查看执行慢的SQL语句(慢查询)

    查看执行慢的SQL语句,需要先开启慢查询日志,MySQL的慢查询日志,记录在MySQL中响应时间超过阀值的语句(具体指运行时间超过long_query_time值的SQL,本文给大家介绍MySQL查看执行慢的SQL语句,感兴趣的朋友跟随小编一起看看吧
    2024-03-03
  • 配置Mysql主从服务实现实例

    配置Mysql主从服务实现实例

    这篇文章主要介绍了配置Mysql主从服务实现实例的相关资料,需要的朋友可以参考下
    2017-05-05
  • MySQL重定位数据目录的方法

    MySQL重定位数据目录的方法

    这篇文章主要介绍了MySQL重定位数据目录的实现方法,分析了重定位MySQL数据目录的实现原理与技巧,具有一定的参考借鉴价值,需要的朋友可以参考下
    2014-12-12
  • mysql把一段数据变成一个临时表

    mysql把一段数据变成一个临时表

    这篇文章主要介绍了mysql把一段数据变成一个临时表,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2024-02-02
  • MySQL的表空间是什么

    MySQL的表空间是什么

    这篇文章主要介绍了MySQL的表空间是什么,帮助大家更好的理解和使用MySQL表的相关知识,感兴趣的朋友可以了解下
    2020-11-11
  • 一个 20 秒 SQL 慢查询优化处理方案

    一个 20 秒 SQL 慢查询优化处理方案

    这篇文章主要分享一个 20 秒 SQL 慢查询优化的经历与处理方案,页面无法正确获取数据,经排查原来是接口调用超时,而最后发现是因为SQL查询长达到20多秒而导致了问题的发生,下面来看问题具体介绍吧
    2022-01-01

最新评论