mysql8全文检索

文章目录

参考

  1. 自然语言搜索

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

  2. 分词长度

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

    https://dev.mysql.com/doc/refman/8.4/en/server-system-variables.html#sysvar_ngram_token_size

  3. 最小查询词长度

    https://dev.mysql.com/doc/refman/8.4/en/innodb-parameters.html#sysvar_innodb_ft_min_token_size

  4. 全文检索单表cache

    https://dev.mysql.com/doc/refman/8.4/en/innodb-parameters.html#sysvar_innodb_ft_cache_size

  5. 全文检索总cache

    https://dev.mysql.com/doc/refman/8.4/en/innodb-parameters.html#sysvar_innodb_ft_total_cache_size

  6. 停止词

    https://dev.mysql.com/doc/refman/8.4/en/fulltext-stopwords.html

  7. 其它参考

    https://www.zhihu.com/question/590429721/answer/3612724219

全文检索

bash 复制代码
cat my.cnf
bash 复制代码
#最大值1600M
innodb_ft_total_cache_size=1600M
#最大值80M
innodb_ft_cache_size=80M
#默认值3
innodb_ft_min_token_size=2
#默认值2
ngram_token_size=2

默认分词

默认分词(自然语言分词)默认分词器基于空格、标点符号、停止词的来分隔单词,主要针对英文按单词分词,对中文这种没有空格的语言就难搞。使用方法:CREATE FULLTEXT INDEX idx_content ON articles(content);

或 ALTER TABLE articles ADD FULLTEXT INDEX idx_content(content);

ngram分词

ngram分词器将文本分解成所有可能的连续字符子串(n-gram),其中n是一个指定的数字,表示子串的长度。它不会区分单词边界,因此适用于没有明确单词分隔符的语言,如中文、日文和韩文。它为每个n-gram

创建索引条目,可以用于执行全文搜索

。它适用于中文、日文、韩文等不使用空格分隔单词的语言。适用于需要按字符序列进行搜索的场景。 Mysql默认ngram分词器的长度为2:

查询默认ngram分词器的长度:

sql 复制代码
show VARIABLES like 'ngram_token_size'

设置默认ngram分词器的长度:

sql 复制代码
SET GLOBAL ngram_token_size = 2;

测试样例

sql 复制代码
ALTER TABLE `report_information`
ADD FULLTEXT INDEX `idx_account` (`account`) WITH PARSER ngram ;

ALTER TABLE `report_information`
ADD FULLTEXT INDEX `idx_content` (`content`) WITH PARSER ngram ;
sql 复制代码
select information_id, account  from report_information
 where MATCH (account) against ('+星星' IN NATURAL LANGUAGE MODE);
sql 复制代码
select information_id, account  from report_information
where MATCH (account) against ('+星星' in Boolean MODE);
sql 复制代码
select information_id, account  from report_information
WHERE MATCH(account) AGAINST('+星星' WITH QUERY EXPANSION);
相关推荐
川石课堂软件测试13 小时前
学习软件测试需掌握的一些知识
数据库·python·sql·功能测试·网络协议·mysql·http
1024奇点20 小时前
【仓颉语言入门 · 第二篇 第 12 课】
开发语言·数据库·ide·mysql·开源
冰暮流星20 小时前
mysql之insert优化
数据库·mysql
北方的银狐-Zero20 小时前
OntoL 7.0|面向工业多智能体的语义本体套件,让异构系统真正 “看懂彼此”——OntoL的本体产品矩阵
人工智能·mysql·sqlite·1024程序员节·本体论·本体产品
瑞克-桑切斯21 小时前
4、MySQL 索引与事务
数据库·mysql
二宝哥1 天前
【问题】本地启动springboot项目启动flowable引擎会提示数据库脚本错误,同事本地启动没有报错(MySQL表明大小写敏感参数)
数据库·mysql
瑞克-桑切斯1 天前
2、 MySQL 主从复制与读写分离
数据库·mysql
秋饼1 天前
MySQL 分库分表完全指南:ShardingSphere-JDBC 实战、分片键选型、场景边界、20 个生产坑与 30 道面试点
java·mysql·面试·shardingsphere·分库分表·后端架构
Elastic 中国社区官方博客1 天前
使用 OpenTelemetry 在 Elastic 中实现 Claude 平台的人工智能 agent 可观测性
大数据·运维·服务器·人工智能·elasticsearch·信息可视化·全文检索