在mysql官网,innodb引擎在5.6.4版本提供了对全文索引的支持,笔者对此做了测试,发现对中文全文检索的支持依然不理想,但却确实提供了对英文的全文支持。
测试过程如下:
1、版本选择,选5.6.27 版。
2、安装完成后,添加全文索引进行测试,表引擎为Innodb
(1)修改ft_min_word_len参数值为1(默认是4,2个汉字)调整全文索引检索字段的最小长度为1个字节;
(2)对表A的content列添加全文索引;
<code>> </code><code>alter</code> <code>table</code> <code>ask_questions </code><code>add</code> <code>fulltext ind_ask_questions_content(content);</code>
查看
<code>>show </code><code>index</code> <code>from</code> <code>ask_questions;</code>
模糊匹配查询,看看包含关键字的行数:
<code>> </code><code>select</code> <code>count</code><code>(*) </code><code>from</code> <code>ask_questions </code><code>where</code> <code>content </code><code>like</code> <code>'%xxx%'</code><code>;</code>
一共有182行,其中包括四种情况:'%xxx%','%xxx','xxx%','xxx'。
在全文索引查看的时候只能对 'xxx' 这种情况进行检索,其他的行由于汉字与英文字母的断字不一样而忽略掉了;
<code>select</code> <code>* </code><code>from</code> <code>ask_questions </code><code>where</code> <code>MATCH(content) AGAINST (</code><code>'好玩吗'</code><code>) </code><code>order</code> <code>by</code> <code>id limit 10;</code>
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiInBnaukDOzgzMxcTNycjM5EDOx8CX0ADNxAjMvwFN1gzN5UzLcl2Lc12bj5yZvxmY0lmbj5ycldWYtl2Lc9CX6MHc0RHaiojIsJye.jpg)
但是其中的行,比如不被空格,"?"等隔开的行,是不会被检索出来的:
<code>> </code><code>select</code> <code>* </code><code>from</code> <code>ask_question_bak </code><code>where</code> <code>content </code><code>like</code> <code>'%好玩吗%'</code> <code>limit 10;</code>
我们可以通过查看id列看出来差别;
3、myisam中的中文全文索引测试;
对于mysql自带的功能,也是一样的,支持并不是很好。
4、myisam安装mysqlcft插件,测试对中文全文索引的支持;
(1) 解压,安装plugin。
查看插件目录:
<code>> show variables </code><code>like</code> <code>'%plugin%'</code><code>;</code>
(2)解压,把mysqlcfg.so文件cp到这个目录下,安装plugin
<code>> INSTALL PLUGIN mysqlcft SONAME </code><code>'mysqlcft.so'</code><code>;</code>
(3)查看。
<code>> </code><code>select</code> <code>* </code><code>from</code> <code>mysql.plugin;</code>
安装mysqlcft插件成功;
测试查看查询数目与模糊查询一致,效率提高了300倍左右;
本文转自crazy_charles 51CTO博客,原文链接:http://blog.51cto.com/douya/1732130,如需转载请自行联系原作者