MySQL必知必会之15-20(三)

2014-11-24 10:57:14 · 作者: · 浏览: 4
e added.

Comment forwarded to vendor. | 0 |

+-------------------------------------------------------------------------------

-----------------------------------------------------------------------------+--

----------------+

14 rows in set (0.03 sec)

这里,在SELECT而不是WHERE子句中使用Match()和Against()。这使所有行都被返回。Match()和Against()用来建立一个计算列,此列包含全文本搜索计算出的等级值。等级有MySQL根据行中词的数目、唯一词的数目、整个索引中词的总数以及包含该词的行的数目计算出来。

18.2使用查询扩展

查询扩展用来设法房款所返回的全文本搜素结果的范围。在使用查询扩展时,MySQL对数据和索引进行两边扫描来完成搜索:

1) 首先,进行一个基本的全文本搜索,找粗与搜索条件匹配的所有行

2) 其次,MySQL检查这些匹配行并进行选择所有有用的词(我们将会简要地解释MySQL如何判定什么有用,什么无用)

3) 再其次,MySQL再次进行全文本搜索,这次不仅使用原来的条件,而且还使用所有有用的词

mysql> select note_text FROMproductnotes WHERE Match(note_text) Against('anvils

' WITH QUERY EXPANSION);

+-------------------------------------------------------------------------------

---------------------------------------------------------------------------+

| note_text

|

+-------------------------------------------------------------------------------

---------------------------------------------------------------------------+

| Multiple customer returns, anvils failingto drop fast enough or falling backw

ards on purchaser. Recommend that customerconsiders using heavier anvils. |

| Customer complaint:

Sticks not individually wrapped, too easyto mistakenly detonate all at once.

Recommend individual wrapping. |

| Customer complaint:

Not heavy enough to generate flying starsaround head of victim. If being purcha

sed for dropping, recommend ANV02 or ANV03instead. |

| Please note that no returns will beaccepted if safe opened using explosives.

|

| Customer complaint: rabbit has been ableto detect trap, food apparently less

effective now. |

| Customer complaint:

Circular hole in safe floor can apparentlybe easily cut with handsaw.

|

| Matches not included, recommend purchaseof matches or detonator (item DTNTR).

|

+-------------------------------------------------------------------------------

---------------------------------------------------------------------------+

7 rows in set (0.00 sec)

这里第一行包含词anvils,因此等级最高。第二行与anvils无关,但因为它包含第一行中的两个词(customer和recommend),所以也被检索出来。接下去的几行也会如此。

18.3布尔文本搜索

MySQL支持全文本搜索的另外一种形式,布尔搜索,可以提供如下内容的细节:

1) 要匹配的词

2) 要排斥的词(如果某行包含这种词,则不返回改行,即使它包含要匹配的词)

3) 排列提示(指定某些词比其他次更重要,更重的词等级更高)

4) 表达式分组

5) 另外一些内容

布尔方式不同于一般的全文本搜索的地方在于:即使没有定义FULLTEXT索引,也可以使用它。

布尔操作符与说明如下:

+ 包含,词必须存在

- 排除,词必须不出现

> 包含,而且增加等级值

< 包含,且减少等级值

() 把词组成子表达式

~ 取消一个词的排序值

* 词尾的通配符

“ ” 定义一个短语

SELECT note_text FROM productnotes WHERE Match(note_text)Against('heavy' IN BOOLEAN MODE);//输出结果如下

+-------------------------------------------------------------------------------

---------------------------------------------------------------------------+

| note_text

|

+-------------------------------------------------------------------------------

---------------------------------------------------------------------------+

| Item is extremely heavy. Designed fordropping, not recommended for use with s

lings, ropes, pulleys, or tightropes. |

| Customer complaint:

Not heavy enough to generate flying starsaround head of victim. If being purcha

sed for dropping, recommend ANV02 or ANV03instead. |

+-------------------------------------------------------------------------------

---------------