两个最常使用引擎:InnoDB和MyISAM
其中,InnoDB不支持全文本搜索。只有MyISAM支持,注意!
LIKE通配符只能匹配已知包含此文本的行,正则化匹配可查找更加复杂的匹配模式。
通配符博客地址:https://blog.csdn.net/m0_38061639/article/details/82833196
正则化匹配博客地址:https://blog.csdn.net/m0_38061639/article/details/82845461
但LIKE通配符和正则化匹配仍存在一些限制:
传递给Match()的值必须与FULLTEXT()中的相同,即Match括号中必须是FULLTEXT,即有索引的列。如果要指定多列,需要按顺序列出。
SELECT note_text FROM productnotes WHERE Match(note_text) Against('rabbit');
SELECT note_text FROM productnotes WHERE note_text LIKE '%rabbit%';
SELECT note_text,Match(note_text) Against('rabbit') as ranks FROM productnotes ORDER BY ranks DESC;
4.1 用简单的WHERE LIKE,只有1条结果
SELECT note_text FROM productnotes WHERE note_text LIKE '%anvils%';
4.2 使用查询扩展
有7行结果,但其实只有第一行包含了anvils这个词,其他行不包括。但第二行包含了第一行的两个词:customer和recommend。
SELECT note_text FROM productnotes
WHERE Match(note_text) Against('anvils' WITH QUERY EXPANSION);
评估查询扩展:返回的行越多,扩展查询越好,但同时也增加了不想要的行。
布尔方式(Boolean mode),没有FULLTEXT索引也可以用,但是操作很慢。
了解掌握不同布尔操作符的含义。
表来自《MySQL必知必会》第18章
5.1 包含rabbit或bait的行
SELECT note_text FROM productnotes
WHERE Match(note_text) Against('rabbit bait' IN BOOLEAN MODE);
5.2 - *
包含heavy,且不包含所有有rope开头的词的行:
SELECT note_text FROM productnotes
WHERE Match(note_text) Against('heavy -rope*' IN BOOLEAN MODE);
5.3 +
必须包含rabbit和bait的行
SELECT note_text FROM productnotes
WHERE Match(note_text) Against('+rabbit +bait' IN BOOLEAN MODE);
5.4 “”
包括短语“rabbit bait”的行
SELECT note_text FROM productnotes
WHERE Match(note_text) Against('"rabbit bait"' IN BOOLEAN MODE);
5.5 ><增加或降低等级
匹配rabbit和carrot,增加前者等级,降低后者等级
SELECT note_text FROM productnotes
WHERE Match(note_text) Against('>rabbit <carrot' IN BOOLEAN MODE);
5.6 ()
降低后者等级
SELECT note_text FROM productnotes
WHERE Match(note_text) Against('+safe +(<combination)' IN BOOLEAN MODE);