mysql数据库全文索引 ngram 分词的使用方法和列子
程序员文章站
2022-07-01 09:20:18
...
使用准备:
#mysql版本必须大于5.7
在mysql配置文件my.ini里面添加ngram_token_size=2 2这个值代表按两个汉字长度分词
[mysqld]
ngram_token_size=2
使用方法:
#创建全文索引并分词
#ALTER TABLE article ADD FULLTEXT INDEX ft_index (title,intro) WITH PARSER ngram;
#查询并按相关性排序
#SELECT id,title FROM article WHERE MATCH (title,intro) AGAINST ('筷子要吃饭' IN NATURAL LANGUAGE MODE)
#查询相关性值
#SELECT id,title,MATCH (title,intro) AGAINST ('筷子要吃饭' IN NATURAL LANGUAGE MODE) AS score FROM article ORDER BY score desc;