一,创建索引
CREATE FULLTEXT INDEX ft_content ON table_name (content) WITH PARSER ngram;
表名和字段可以用``表示引用
说明:创建全文索引时,如果不添加WITH PARSER ngram;
有可能会检索不到结果
二,测试:
1,包含指定的词:
SELECT * FROM `table_name` WHERE MATCH(content) against ('关键词') ORDER by id DESC
2, 包含任一个词:
SELECT * FROM `table_name` WHERE MATCH(content) against ('关键词1 关键词2') ORDER by id DESC
也可以用下面的形式
SELECT * FROM `table_name` WHERE MATCH(content) against ('关键词1 关键词2' in boolean MODE) ORDER by id DESC
3,
两个词必需同时包含:
SELECT * FROM table_name WHERE MATCH(content) against ('+关键词1 +关键词2' in boolean MODE) ORDER by id DESC