zno2

MySQL 全文索引 (极不实用)(不推荐)

内置分词器

https://dev.mysql.com/doc/refman/5.7/en/fulltext-search-ngram.html

语法

https://dev.mysql.com/doc/refman/5.7/en/fulltext-search.html

简介

https://dev.mysql.com/doc/refman/5.7/en/innodb-fulltext-index.html

 

 

为什么不用MySQL 全文检索?

答:入参一定会分词查询,就这一条就无法使用。有一种场景是like,但是需要高效,不幸的是不支持

为什么要用elasticsearch ?

 

实践一下

drop table if exists goods;

/*==============================================================*/
/* Table: goods                                                 */
/*==============================================================*/
create table goods
(
   `name`                 varchar(200) comment '名称',
   ad_words             varchar(200) comment '广告词'
);


# 这里如果用到了多个字段,match的时候也需要多个字段 
CREATE FULLTEXT INDEX fidx_adwords ON goods (`name`,ad_words) WITH PARSER ngram;


insert into goods(`name`,ad_words) values ('李宁','一切皆有可能');

# https://dev.mysql.com/doc/refman/5.7/en/fulltext-natural-language.html
# 默认大小写不敏感
# 排序按匹配得分
# 入参也会分词
# 这个模式'随缘'匹配
# 不指定模式时默认使用该模式 
select * from goods where MATCH ( `name`, ad_words ) AGAINST ('李宁一切皆有可能' IN NATURAL LANGUAGE MODE ); # https://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html # 这个模式需要使用各种条件语法,然后严格匹配 select * from goods where MATCH ( `name`, ad_words ) AGAINST ('+可能 -耐克' IN BOOLEAN MODE );

 

posted on 2023-06-02 08:18  zno2  阅读(55)  评论(0编辑  收藏  举报

导航