Mysql全文本搜索

引擎的支持

mysql全文本搜索需要myisam存储引擎,innodb引擎不支持。
在建表的时候启用fulltext索引
如:

create table productnotes(
    note_id int not null auto_increament,
    pro_id char(10) not null,
    note_date datetime not null,
    note_text text null,
    primary key(note_id),
    fulltext(note_text)
)engine=myisam;

在索引之后,使用函数match()指定被搜索的列,使用函数against()指定要搜索的表达式。
如:

select note_text from productnotes where match(note_text) against('rabbit');

搜索note_text列含有rabbit字符的所有行。
虽然说这种查询用简单的like模糊查询也能办到,到效率上,索引执行相当快。

查询扩展(with query expansion)

select note_text from productnotes where match(note_text) against('rabbit' with query expansion)

布尔文本搜索(in boolean mode)

包含heavy字符

select note_text from productnotes where match(note_text) against('heavy' in boolean mode);

为了匹配包含heavy但不包含任意以rope开始的词的行,可使用如下:

select note_text from productnotes where match(note_text) against('heavy -rope*' in boolean mode);

-rope* 表示排除以rope开始的词

全文本布尔操作符

这里写图片描述

举例:
这里写图片描述

这里写图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黄宝康

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值