首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

MYSQL入门学习之三:满篇本搜索

2012-12-16 
MYSQL入门学习之三:全文本搜索一、理解全文本搜索1、MyISAM支持全文本搜索,而InnoDB不支持。2、在使用全文本搜

MYSQL入门学习之三:全文本搜索

一、理解全文本搜索

1、MyISAM支持全文本搜索,而InnoDB不支持。

2、在使用全文本搜索时,MySQL不需要分别查看每个行,不需要分别分析和处理每个词。MySQL创建指定列中各词的一个索引,搜索可以针对这些词进行。这样MySQL可以快速有效地决定哪些词匹配,哪些词不匹配,它们匹配的频率,等等。

二、使用全文本搜索

1、为了进行全文本搜索,必须索引被搜索的列,而且要随着数据的改变不断地重新索引。在对表列进行适当设计后,MySQL会自动进行所有的索引和重新索引。

    在索引之后,SELECT可与Match()和Against()一起使用以实际执行搜索。

2、一般在创建表时启用全文本搜索。

mysql> select note_id,note_text    -> fromproductnotes    -> whereMatch(note_text) Against('line' in boolean mode);+---------+------------------------------------------------------+| note_id | note_text                                                         |+---------+------------------------------------------------------+|       5 | This line ofproprietary reagents,. containers, and automation tools is designed. for genomicsand drug discovery .research. ||       7 | specificitiesinclude both alpha–beta and beta–beta. This line from chromatography .data systems (CDSs) and to LIMS.       |+---------+------------------------------------------------------+2 rows in set (0.00 sec)    即使没有FULLTEXT索引也可以使用布尔文本搜索。但是非常缓慢。mysql> select note_id,note_text/*匹配line且不包含systems*/    -> fromproductnotes    -> whereMatch(note_text) Against('line -systems*' in boolean mode);+---------+------------------------------------------------------+| note_id | note_text                                                        |+---------+------------------------------------------------------+|       5 | This line ofproprietary reagents,. containers, and automation tools is designed. forgenomics and drug discovery .research. |+---------+------------------------------------------------------+1 row in set (0.00 sec) mysql> select note_id,note_text/*匹配line且匹配systems*/    -> fromproductnotes    -> whereMatch(note_text) Against('+line +systems' in boolean mode);+---------+------------------------------------------------------------------------------------+| note_id | note_text                                                  |+---------+------------------------------------------------------------------------------------+|       7 | specificitiesinclude both alpha–beta and beta–beta. This line from chromatography .data systems (CDSs) and to LIMS. |+---------+------------------------------------------------------------------------------------+1 row in set (0.00 sec) mysql> select note_id,note_text/*匹配line或匹配systems*/    -> fromproductnotes    -> whereMatch(note_text) Against('line systems' in boolean mode);+---------+------------------------------------------------------+| note_id | note_text                                                        |+---------+------------------------------------------------------+|       5 | This line ofproprietary reagents,. containers, and automation tools is designed. forgenomics and drug discovery .research. ||       6 | LimsLink is.designed to interface output. from chromatography .data systems (CDSs) and toLIMS.                             ||       7 | specificitiesinclude both alpha–beta and beta–beta. This line from chromatography .data systems (CDSs) and to LIMS.       |+---------+------------------------------------------------------+3 rows in set (0.00 sec) mysql> select note_id,note_text/*匹配短语*/    -> fromproductnotes    -> whereMatch(note_text) Against('"This line"' in boolean mode);+---------+------------------------------------------------------+| note_id | note_text                                                        |+---------+------------------------------------------------------+|       5 | This line ofproprietary reagents,. containers, and automation tools is designed. forgenomics and drug discovery .research. ||       7 | specificitiesinclude both alpha–beta and beta–beta. This line from chromatography .data systems (CDSs) and to LIMS.       |+---------+------------------------------------------------------+2 rows in set (0.00 sec)

10、使用说明

l  在索引全文本数据时,短词被忽略且从索引中排除。短词的定义为那些具有3个或脸上以下字符的词(如果需要,这个数目可以更新)。

l  MySQL带有一个内建的非用词(stopword)列表,这些词在索引全文本数据时总是被忽略。如果需要,可以覆盖这个列表。

l  MySQL规定了一条50%规则,如果一个词出现在50%以上的行中,则将它作为一个非用词忽略。50%规则不用于IN BOOLEAN MODE。

l  如果表中的行数少于3行,则全文本搜索不返回结果(因为每个词或者不出现,或者至少出现在50%的行中)。

l  忽略词中的单引号。如,don’t索引为dont。

l  不具有词分隔符的语言不能恰当地返回全文本搜索结果。

热点排行