MySQL 全文索引实现一个简单版搜索引擎( 三 )


需先在my.cnf 配置文件中设置ngram_token_size(默认为2 , 2个字符作为ngram 的关键词) , 并重启mysql服务
这里使用默认的 2
select title from article limit 10;+------------------------------------------------------------------------------+| title                                                                        |+------------------------------------------------------------------------------+| worth IT                                                                    ||Launchpad 江南皮革厂小show                                                  ||Raw 幕后罕见一刻 “疯子”被抬回后台                                           ||Raw:公子大骂老爸你就是个绿茶  公子以一打四                                  ||四组30平米精装小户型 , 海量图片 , 附户型图                                    ||夜店女王性感烟熏猫眼妆                                                      ||大秀哥重摔“巨石”强森                                                        ||少女时代 崔秀英 服饰科普 林允儿 黄美英 金泰妍 郑秀晶                        |                                              |德阳户外踏青 , 花田自助烧烤                                                  |+------------------------------------------------------------------------------+2、对title字段创建全文索引
alter table article add fulltext index ft_index_title(title) with parser ngram;Query OK, 0 rows affected (3 min 29.22 sec)Records: 0  Duplicates: 0  Warnings: 03、会创建倒排索引(title字段越长长 , 创建的倒排索引越大)

112M Jul 5 21:46 FTS_00000000000000a7_00000000000000cd_INDEX_1.ibd28M Jul 5 21:46 FTS_00000000000000a7_00000000000000cd_INDEX_2.ibd20M Jul 5 21:46 FTS_00000000000000a7_00000000000000cd_INDEX_3.ibd140M Jul 5 21:46 FTS_00000000000000a7_00000000000000cd_INDEX_4.ibd128M Jul 5 21:46 FTS_00000000000000a7_00000000000000cd_INDEX_5.ibd668M Jul 5 21:46 FTS_00000000000000a7_00000000000000cd_INDEX_6.ibd
4、不建立全文索引搜索title的某个关键词


推荐阅读