MySQL.MATCH() AGAINST()全文本搜索

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. |
+----------------------------------------------------------------------------------------------------------------------+
SELECT note_text
    -> FROM productnotes
    -> WHERE note_text LIKE ‘%rabbit%‘;
+----------------------------------------------------------------------------------------------------------------------+
| note_text                                                                                                            |
+----------------------------------------------------------------------------------------------------------------------+
| Quantity varies, sold by the sack load.
All guaranteed to be bright and orange, and suitable for use as rabbit bait. |
| Customer complaint: rabbit has been able to detect trap, food apparently less effective now.                         |
+----------------------------------------------------------------------------------------------------------------------+

SELECT note_text, Match(note_text) Against(‘rabbit‘) AS rank
    -> FROM productnotes;
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------+
| note_text                                                                                                                                                 | 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 |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------+

SELECT note_text
    -> FROM productnotes
    -> WHERE MATCH(note_text) Against(‘anvils‘);
+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| note_text                                                                                                                                                |
+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| Multiple customer returns, anvils failing to drop fast enough or falling backwards on purchaser. Recommend that customer considers using heavier anvils. |
+----------------------------------------------------------------------------------------------------------------------------------------------------------+

SELECT note_text
    -> FROM productnotes
    -> WHERE MATCH(note_text) AGAINST(‘anvils‘ WITH QUERY EXPANSION);
+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| note_text                                                                                                                                                |
+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| Multiple customer returns, anvils failing to drop fast enough or falling backwards on purchaser. Recommend that customer considers using heavier anvils. |
| Customer complaint:
Sticks not individually wrapped, too easy to mistakenly detonate all at once.
Recommend individual wrapping.                         |
| Customer complaint:
Not heavy enough to generate flying stars around head of victim. If being purchased for dropping, recommend ANV02 or ANV03 instead.  |
| Please note that no returns will be accepted if safe opened using explosives.                                                                            |
| Customer complaint: rabbit has been able to detect trap, food apparently less effective now.                                                             |
| Customer complaint:
Circular hole in safe floor can apparently be easily cut with handsaw.                                                               |
| Matches not included, recommend purchase of matches or detonator (item DTNTR).                                                                           |
+----------------------------------------------------------------------------------------------------------------------------------------------------------+

SELECT note_text
    -> FROM productnotes
    -> WHERE MATCH(note_text) AGAINST(‘heavy‘ IN BOOLEAN MODE);
+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| note_text                                                                                                                                               |
+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| Item is extremely heavy. Designed for dropping, not recommended for use with slings, ropes, pulleys, or tightropes.                                     |
| Customer complaint:
Not heavy enough to generate flying stars around head of victim. If being purchased for dropping, recommend ANV02 or ANV03 instead. |
+---------------------------------------------------------------------------------------------------------------------------------------------------------+

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. |
+---------------------------------------------------------------------------------------------------------------------------------------------------------+

SELECT note_text
    -> FROM productnotes
    -> WHERE MATCH(note_text) AGAINST(‘+rabbit +bait‘ IN BOOLEAN MODE);
+----------------------------------------------------------------------------------------------------------------------+
| note_text                                                                                                            |
+----------------------------------------------------------------------------------------------------------------------+
| Quantity varies, sold by the sack load.
All guaranteed to be bright and orange, and suitable for use as rabbit bait. |
+----------------------------------------------------------------------------------------------------------------------+

SELECT note_text FROM productnotes WHERE MATCH(note_text) AGAINST(‘rabbit bait‘ IN BOOLEAN MODE);
+----------------------------------------------------------------------------------------------------------------------+
| note_text                                                                                                            |
+----------------------------------------------------------------------------------------------------------------------+
| Quantity varies, sold by the sack load.
All guaranteed to be bright and orange, and suitable for use as rabbit bait. |
| Customer complaint: rabbit has been able to detect trap, food apparently less effective now.                         |
+----------------------------------------------------------------------------------------------------------------------+

-- 匹配短语rabbit bait而不是匹配两个词rabbit和bait
SELECT note_text FROM productnotes WHERE MATCH(note_text) AGAINST(‘"rabbit bait"‘ IN BOOLEAN MODE);
+----------------------------------------------------------------------------------------------------------------------+
| note_text                                                                                                            |
+----------------------------------------------------------------------------------------------------------------------+
| Quantity varies, sold by the sack load.
All guaranteed to be bright and orange, and suitable for use as rabbit bait. |
+----------------------------------------------------------------------------------------------------------------------+

-- 增加前者的等级,降低后者的等级
SELECT note_text FROM productnotes WHERE MATCH(note_text) AGAINST(‘>rabbit <bait‘ IN BOOLEAN MODE);
+----------------------------------------------------------------------------------------------------------------------+
| note_text                                                                                                            |
+----------------------------------------------------------------------------------------------------------------------+
| Quantity varies, sold by the sack load.
All guaranteed to be bright and orange, and suitable for use as rabbit bait. |
| Customer complaint: rabbit has been able to detect trap, food apparently less effective now.                         |
+----------------------------------------------------------------------------------------------------------------------+

-- 降低后者的等级
SELECT note_text FROM productnotes WHERE MATCH(note_text) AGAINST(‘+safe +(<combination)‘ IN BOOLEAN MODE);
+---------------------------------------------------------------------------------------------------------------------------------------------------+
| note_text                                                                                                                                         |
+---------------------------------------------------------------------------------------------------------------------------------------------------+
| Safe is combination locked, combination not provided with safe.
This is rarely a problem as safes are typically blown up or dropped by customers. |
+---------------------------------------------------------------------------------------------------------------------------------------------------+
时间: 2025-01-26 20:22:19

MySQL.MATCH() AGAINST()全文本搜索的相关文章

MySQL数据检索+查询+全文本搜索

[0]README 0.1)本文部分文字描述转自"MySQL 必知必会",旨在review"MySQL数据检索+查询+全文本搜索" 的基础知识: [1]使用子查询 1)查询定义:任何sql 语句都是查询.但此术语一般指 select语句:SQL 还允许创建子查询,即嵌套在其他查询中的查询: 2)利用子查询进行过滤(where子句,in子句) 2.1)可以把一条select语句返回的结果用于另一条select语句的where子句: 3)作为计算字段使用子查询 3.1)

【转】MYSQL入门学习之三:全文本搜索

转载地址:http://www.2cto.com/database/201212/173873.html 一.理解全文本搜索 www.2cto.com 1.MyISAM支持全文本搜索,而InnoDB不支持. 2.在使用全文本搜索时,MySQL不需要分别查看每个行,不需要分别分析和处理每个词.MySQL创建指定列中各词的一个索引,搜索可以针对这些词进行.这样MySQL可以快速有效地决定哪些词匹配,哪些词不匹配,它们匹配的频率,等等. 二.使用全文本搜索 1.为了进行全文本搜索,必须索引被搜索的列,

数据库9:联结表 高级联结 组合查询 全文本搜索

第十五章联结表 Sql最强大的功能之一就是能在数据检索查询的执行中联结(join)表.联结是利用sql的select能执行的最重要的操作,能很好的理解联结及其语法是学习sql的一个极为重要的组成部分.   外键:外键为某个表中的一列,它包含另一个表的主键值,定义了两个表之间的关系. 好处:供应商信息不重复,不浪费空间和时间,方便日后修改,一个表信息改动不影响另一个表的信息 联结是一种机制,使用特殊的语法,可以联结多个表返回一组输出,联结在运行时关联表中正确的行.   创建联结          

第十八章 全文本搜索

1.使用like和regexp进行文本的搜索有几个缺点: A:性能不高,通配符和正则表达式通常要求mysql尝试匹配表中所有行,由于行数多,这些搜索可能很耗时 B:使用正则表达式和通配符很难明确空值 C:虽然基于通配符和正则表达式的搜索提供了非常灵活的效率,但它们都不能提供一种智能化的选择结果 2.为了进行全文本搜索,必须索引被搜索的列,而且随着数据的改变不断重新索引.在索引之后select可与match()和against()一起使用. 3.一般在创建表时启用全文本搜索.create tabl

全文本搜索

仅在MyISAM引擎中支持全文本搜索 1.创建表时启用全文本搜索 e.g. CREATE TABLE productnotes ( note_id int NOT NULL AUTO_INCREMENT, prod_id char(10) NOT NULL, note_text text NULL, PRIMARY KEY(note_id), FULLTEXT(note_text) )ENGINE=MyISAM 这里FULLTEXT一个列,也可以指定多个列,用逗号隔开 2.索引之后,使用Matc

第十八章:全文本搜索

@author: Tobin @date: 2019/11/4 16:03:15 MyISAM不支持全文本搜索,InnoDB支持. # 在创建表时启用全文本搜索 CREATE TABLE productnotes ( note_id int NOT NULL AUTO_INCREMENT, prod_id char(10) NOT NULL, note_date datetime NOT NULL note_text text NULL, PRIMARY KEY(note_id), FULLTE

mysql 文本搜索

全文本搜索 MySQL支持几种基本的数据库引擎,但并非所有的引擎都支持全文本搜索.两个最常使用的引擎为MyISAM和InnoDB,前者支持全文本搜索,后者就不支持. 理解全文本搜索 在前面的学习中,我们都知道有两种方式来匹配文本.一种是使用like关键字来进行匹配,另外一种就是使用正则表达式来进行匹配. 虽然使用正则表达式就可以编写查找所需行的足够复杂的匹配模式.但是,这些存在几个重要的限制影响: 1.性能:通配符和正则表达式时尝试匹配表中所有行,而这些搜索极少使用了表索引,因此,相当慢 2.明

Linux下文本搜索工具grep命令使用入门

grep命令入门 如果想通过使用grep命令来实现理想化的文本搜索,对正则表达式的了解是比不可少的.文献1对正则表达式语法做了一个简单的介绍,文献2提供了一个简单的入门.码农也可以自己google一下其他的参考资料.下面就grep命令的使用做个入门级的介绍. 1.1 grep命令的变种 linux下除了grep命令可以完成文本搜索外,还存在egrep,fgrep,rgrep三个命令.这三个命令都是由grep加上一些控制参数演变而来,如egrep=grep -E, fgrep=grep -F, r

MySQL 索引优化全攻略

所谓索引就是为特定的mysql字段进行一些特定的算法排序,比如二叉树的算法和哈希算法,哈希算法是通过建立特征值,然后根据特征值来快速查找.而用的最多,并且是mysql默认的就是二叉树算法 BTREE,通过BTREE算法建立索引的字段,比如扫描20行就能得到未使用BTREE前扫描了2^20行的结果,具体的实现方式后续本博客会出一个算法专题里面会有具体的分析讨论; Explain优化查询检测 EXPLAIN可以帮助开发人员分析SQL问题,explain显示了mysql如何使用索引来处理select语