启用全文本搜索支持:
CREATE TABLE productnotes
(
note_id int NOT NULL auto_increment,
prod_id char(10) NOT NULL,
note_date datetime NOT NULL,
note_text text NULL,
PRIMARY KEY(note_id),
FULLTEXT(note_text)
) ENGINE = MyISAM;
进行全文本搜索:
SELECT note_text
FROM productnotes
WHERE Match(note_text) Against('rabbit'); -- 传递给Match()的值必须与FULLTEXT()定义中的相同
使用查询扩展:
SELECT note_text
FROM productnotes
WHERE Match(note_text) Against('anvils' WITH QUERY EXPANSION);
布尔文本搜索:
SELECT note_text
FROM productnotes
WHERE Match(note_text) Against('heavy' IN BOOLEAN MODE);
布尔操作符:
-:排除,词必须不出现
SELECT note_text
FROM productnotes
WHERE Match(note_text) Against('heavy -rope*' IN BOOLEAN MODE); -- 排除包含rope*(任何以rope开始的词,包括ropes)的行
+:包含,词必须存在
SELECT note_text
FROM productnotes
WHERE Match(note_text) Against('+rabbit +bait' IN BOOLEAN MODE); -- 这个搜索匹配包含词rabbit和bait的行
SELECT note_text
FROM productnotes
WHERE Match(note_text) Against('rabbit bait' IN BOOLEAN MODE); -- 没有指定操作符,这个搜索匹配包含rabbit和bait中的至少一个词的行
“”:定义一个短语
SELECT note_text
FROM productnotes
WHERE Match(note_text) Against('"rabbit bait"' IN BOOLEAN MODE); -- 这个搜索匹配短语rabbit bait而不是匹配两个词rabbit和bait
<>:包含,改变等级值
SELECT note_text
FROM productnotes
WHERE Match(note_text) Against('>rabbit <carrot' IN BOOLEAN MODE); -- 增加前者的等级值,降低后者的等级值
():把词组成子表达式
SELECT note_text
FROM productnotes
WHERE Match(note_text) Against('+safe +(<combination)' IN BOOLEAN MODE); -- 这个搜索匹配词safe和combination,降低后者的等级