56.笔记 MySQL学习——布尔模式全文搜索

56.笔记 MySQL学习——布尔模式全文搜索

通过使用布尔模式的全文搜索,可以获得对多单词搜索的更多控制。要在搜索字符串后面加上IN BOOLEAN MODE。

布尔模式有以下特点:

l  即使找到的单词会出现在一半以上的行里,仍然会把它们搜搜出来

l  查询结果不再按相关程序排序

l  搜索可以要求短语里的所有单词都必须是按某种特定的顺序出现

l  可以对未包括在FULLTEX索引里的那些列,进行布尔模式全文搜索

如果要匹配一个短语,那么需要把它用双引号引起来。只有在行包含的那些单词及其顺序与短语里列出的内容一致时,才会被认为是匹配上了。

如下:

mysql> select * from apothegm wherematch(attribution,phrase) against ( '"bell book and candle"' inboolean mode);

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

| attribution         | phrase                 |

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

| Miguel de Cervantes | Bell, book, andcandle |

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

1 row in set (0.00 sec)

mysql> select * from apothegm wherematch(attribution,phrase) against ( '"book bell and candle"' inboolean mode);

Empty set (0.00 sec)

对于布尔模式搜索,还可以为搜索字符串里的单词加上些修饰符,例如加号,减号。

搜索字符串’bell –candle’只会与那些包含了‘bell’但不包含candle的行

mysql> select * from apothegm wherematch(attribution,phrase) against ('bell');

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

| attribution           | phrase                             |

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

| Alexander Graham Bell | Mr. Watson, comehere. I want you! |

| Miguel de Cervantes   | Bell, book, and candle             |

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

2 rows in set (0.00 sec)

mysql> select * from apothegm wherematch(attribution,phrase) against ('+bell -candle' in boolean mode);

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

| attribution           | phrase                             |

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

| Alexander Graham Bell | Mr. Watson, comehere. I want you! |

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

1 row in set (0.00 sec)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值