参考文档
https://dev.mysql.com/doc/refman/8.0/en/fulltext-search-ngram.html 多元语言模型全文索引
https://dev.mysql.com/doc/refman/8.0/en/innodb-fulltext-index.html 全文索引的建立
https://dev.mysql.com/doc/refman/8.0/en/fulltext-stopwords.html 全文索引停用词的加入
1.需要在mysqld 选项上上添加
#全文索引中文分词
ngram_token_size=2
2. 表中最好含有一个 FTS_DOC_ID字段,否则mysql 会隐式添加一个字段 FTS_DOC_ID
注意,这个字段必须为大写
`FTS_DOC_ID` BIGINT UNSIGNED NOT NULL
#添加索引
ALTER TABLE exam_core_question_content1 ADD FULLTEXT INDEX fti_title (title) WITH PARSER ngram;
# CREATE FULLTEXT INDEX ft_index ON exam_core_question_content1 (title) WITH PARSER ngram;
3.查询
select * from exam_core_question_content1 where match(title) against ('数据库')
#这样查询会把 "数据库" 拆分成 "数据“, “据库” 查询
#如果需要精确查询 需要用到布尔模式
select * from exam_core_question_content1 where match(title) against ('数据库' in boolean mode);
生成的索引文件
相关文档
https://opensource.actionsky.com/20210512-mysql/ 索引设计(全文索引原理)
https://opensource.actionsky.com/20210525-mysql/ 索引设计(使用全文索引) 查询写的不错
https://opensource.actionsky.com/20210623-mysql/ 索引设计(全文索引中文处理)