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);
相关推荐
灯澜忆梦17 小时前
【MySQL10】进阶篇 | 索引_#2性能优化
数据库·sql·mysql·性能优化
油丶酸萝卜别吃21 小时前
MySQL B+ 树查询全过程详解
数据库·mysql
Cry丶1 天前
遗留系统数据迁移实战(九):区域编码迁移与补偿接口设计
mysql·数据治理·数据迁移·区域编码·补偿接口·组织区域
字节跳动数据库1 天前
火山引擎 RDS MySQL 向量索引:把高性能向量检索带到 MySQL 上
人工智能·后端·mysql
小王C语言1 天前
MySQL 库的操作:字符集和校验规则、数据库的增删查改、备份和还原
数据库·mysql
小王C语言1 天前
MySQL 数据类型:数值类型、字符串类型、日期和时间类型、enum 和 set、find_in_set 查询
android·数据库·mysql
夜雪一千1 天前
MySQL的事务是什么?原理、ACID、隔离级别与实战详解
数据库·mysql
Architect_Lee1 天前
mac快速安装mysql
数据库·mysql·macos
Elastic 中国社区官方博客1 天前
Elasticsearch:列式索引模式 - Columnar index mode
大数据·数据库·elasticsearch·搜索引擎·全文检索