《mysql必知必会》学习_第18章

第18章 全文本搜索

P121  #创建一个新表,对表的列进行定义,定义之后,MySQL自动维护该索引#

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;

P121 进行全文搜索 #Match(列)和Against(指定要搜索的文本) ##搜索不区分大小写##

select note_text from productnotes where March(note_text) Against('rabbit');   #定义指定的列是note_text,要搜索的文本是Rabbit 。#

《mysql必知必会》学习_第18章

 P122 相当于like语句,在rabbit前后都加上符号通配符%

select note_text from productnotes where note_text LIKE '%rabbit%';  #表示检索note_text列中含有ranbbit 的值 #

《mysql必知必会》学习_第18章

 P123  检索的词在该文本(该列的某个值)越靠前,等级就越高,较高的行先返回。

select note_text ,March(note_text) against('rabbit') as rank from productnotes ;#没有where语句,所以没有限制条件语句,所有的行都会被返回, March(note_text) against('rabbit')建立了一新列rank,此列计算出了每行的等级值,词的数目,唯一词的数目,整个索引中词的总数以及包含的该词的行的计算,从而定义了这个结果的排列#

《mysql必知必会》学习_第18章

 P125

select note_text from productnotes where Match(note_text) Against('anvils');   #简单的全文检索,检索note_text列含有anvils的行。#

select note_text from productnotes where Match(note_text) Against('anvils' with query expansion); #查询扩展,第一行含有anvils,第二行起没有anvils,但第二行含有第一行的2个词,该2词位置还靠前,所以被扩展到了,而且优先级还第二高。   #

《mysql必知必会》学习_第18章

 select note_text from productnotes where Match(note_text) Against('heavy-rope*' in boolean mode);  #搜索关于heavy的行,排除含有rope的所有词和行 #

  《mysql必知必会》学习_第18章

select note_text from productnotes where Match(note_text) Against('+rabbit+bait' in boolean mode) #匹配词含有rabbit和bait,句子同时出现这两个词为优先级,(书本里面说检索的结果要同时含有这两个词,但是下面的结果中第二个语句里面只是存在rabbit,没有bait???)#

《mysql必知必会》学习_第18章

 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) # 增加前者的等级,降低后者的等级,r b >b r;r>b;r>b r (同时出现r时候的r的位置是排序的关键)#

select note_text from productnotes where Match(note_text) Against('+safe+(<combination) ' in boolean mode) #搜索匹配词safe和combination,降低后者的等级???(明结果明是可以单独出现)#

 《mysql必知必会》学习_第18章

《mysql必知必会》学习_第18章