mysql默认全文索引的分割关键字方式使用空格切割,因为中文不会使用空格作为词语分割,所以需要特别指定切割方式,因此就使用ngram插件
建表语句:
create table t_content
(
id int(11) primary key auto_increment,
content text,
fulltext f_c(content) with parser ngram
);
特别强调:
fulltext f_c(content) with parser ngram
这条语句意识是给content创建一个使用ngram插件的全文索引f_c。
我因为刚刚开始没有写with parser ngram 导致查询效果相当差。
因为使用了ngram插件,所以需要调整ngram_token_size的值。
ngram_token_size官方解释是:
Defines the n-gram token size for the n-gram full-text parser.
The ngram_token_size option isread-only and canonly be modified at startup.
The default value is 2 (bigram). The maximum value is 10.
从官方解释上看该值默认值是2,若需要修改的话需要在在my.cnf里面配置,并且需要重启mysql才能生效。
首先查询ngram当前的值是多少
show variables like '%ngram%';
查询结果是:
show variab