[MySQL] 原生全文检索 fulltext 的简单应用

通过llama.cpp与羊驼聊天的网页界面- 详解 Serge 的启动使用

 

在目标字段上添加全文检索:alter table 表名 add fulltext(字段) with parser ngram

 

查询语句:select * from xxx where match(字段) against ('检索词' in natural language mode)

 

查看词的权重:SELECT content,match(content) against ('生化危机之战神再生' in natural language mode) as score FROM `xxx` WHERE match(content) against ('生化危机之战神再生' in natural language mode) ;

 

多字段和多个词检索:select * from xxx where match(字段1, 字段2) against ('检索词1 检索词2' in natural language mode)

检索词之间空格隔开代表 “或” 查询。

 

ngram全文检索插件用于非英文单词的分词 (比如中文),支持 InnoDB 和 MyISAM。

比较明显的缺点是全文检索会查出相关的一系列数据,准确性不够精确。

 

另外,建议不要调用外部分词程序然后再进行数据库 “或” 匹配查询,会降低检索效率。

 

Doc:https://dev.mysql.com/doc/refman/8.0/en/fulltext-natural-language.html

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

Link:https://www.cnblogs.com/farwish/p/14406662.html

posted on 2021-02-16 14:45  ercom  阅读(222)  评论(0编辑  收藏  举报