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);
相关推荐
wujt88885 小时前
mysql 比较数据库
数据库·mysql·oracle
小江的记录本15 小时前
【Java基础】泛型:泛型擦除、通配符、上下界限定(附《思维导图》+《面试高频考点清单》)
java·数据结构·后端·mysql·spring·面试·职场和发展
bqq1986102618 小时前
MySQL 8与MySQL 5.7的主要区别
数据库·mysql
chushiyunen18 小时前
r树索引、mysql对r树的支持
数据库·mysql
罗超驿19 小时前
16.深入理解数据库事务:从转账场景剖析ACID四大特性与回滚(Rollback)机制
数据库·mysql
@nengdoudou20 小时前
KingbaseES数据库MySQL模式使用 “GROUP BY“
数据库·mysql
Wait....21 小时前
死锁的知识总结
数据库·mysql
逻辑羊驼1 天前
VSCODE 连接 MySQL 数据库并执行当地SQL文件
数据库·mysql
夜白宋1 天前
【Mysql深入】二、事务
数据库·mysql