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 存储过程输入输出参数示例

    mysql 存储过程输入输出参数示例

    创建存储过程时可以输入输出参数,下面是一个mysql存储过程的创建示例,需要的朋友可以参考下
    2014-08-08
  • 实现MySQL数据库锁的两种方式

    实现MySQL数据库锁的两种方式

    今天我们就来聊一聊数据库的锁,实现数据库锁的两种方式,一个是实现乐观锁的方式,一个是实现悲观锁的实现方式,文中的代码示例介绍的非常详细,需要的朋友可以参考下
    2023-06-06
  • MySQL双主(主主)架构配置方案

    MySQL双主(主主)架构配置方案

    这篇文章主要介绍了MySQL双主(主主)架构配置方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-03-03
  • MYSQL  group by 有哪些注意事项

    MYSQL  group by 有哪些注意事项

    这篇文章主要介绍了MYSQL  group by 有哪些注意事项,比如我们不能在 group by 之后添加 where 查询语句,更多相关分享,需要的朋友可以参考下面文章内容
    2022-07-07
  • MySql约束超详细介绍

    MySql约束超详细介绍

    MySQL唯一约束(Unique Key)是指所有记录中字段的值不能重复出现。例如,为 id 字段加上唯一性约束后,每条记录的 id 值都是唯一的,不能出现重复的情况
    2022-09-09
  • MySQL 8.0.29 解压版安装配置方法图文教程

    MySQL 8.0.29 解压版安装配置方法图文教程

    这篇文章主要为大家详细介绍了MySQL 8.0.29 解压版安装配置方法图文教程,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-06-06
  • MySQL存储过程中使用动态行转列

    MySQL存储过程中使用动态行转列

    这篇文章主要为大家介绍了MySQL存储过程中使用动态行转列的相关资料,需要的朋友可以参考下
    2016-01-01
  • MYSQL必知必会读书笔记第六章之过滤数据

    MYSQL必知必会读书笔记第六章之过滤数据

    本文给大家分享MYSQL必知必会读书笔记第六章之过滤数据的相关知识,非常实用,特此分享到脚本之家平台,供大家参考
    2016-05-05
  • MYSQL拒绝访问报错not allowed to connect

    MYSQL拒绝访问报错not allowed to connect

    MYSQL拒绝访问报错not allowed to connect,下面有个可行的方法,可以在其它任何的主机上以root身份登录
    2014-07-07
  • 深入浅出讲解MySQL的并行复制

    深入浅出讲解MySQL的并行复制

    这篇文章主要给大家介绍了关于MySQL并行复制的相关资料,文中通过示例代码介绍的非常详细,对大家学习或使用mysql具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2018-08-08

最新评论