55.笔记 MySQL学习——自然语言FULLTEXT搜索

55.笔记 MySQL学习——自然语言FULLTEXT搜索

用AGAINST()指定搜索字符串,对表进行自然语言类型的全文搜索,如下:

mysql> select * from apothegm wherematch(attribution) against ('roosevelt');

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

| attribution        | phrase                             |

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

| Theodore Roosevelt | Speak softly andcarry a big stick |

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

1 row in set (0.00 sec)

mysql> select * from apothegm where match(phrase)against ('time');

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

| attribution       | phrase                                    |

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

| Benjamin Franklin | Remember that time ismoney               |

| Aeschylus         | Time as he grows old teaches manylessons |

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

2 rows in set (0.00 sec)

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 where match(phrase)against('hard soft');

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

| attribution         | phrase                                              |

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

| Benjamin Franklin   | It is hard for an empty bag to standupright        |

| Proverbs 15:1       | A soft answer turneth away wrath                    |

| William Shakespeare | But, soft! whatlight through yonder window breaks? |

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

3 rows in set (0.00 sec)

自然语言默认是全文搜索模式。如果想要显示地指定这个模式,可以再字符串后面加上IN NATURAL LANGUAGE MODE。

mysql> select * from apothegm where  match(phrase) against('hard soft' in naturallanguage mode);

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

| attribution         | phrase                                              |

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

| Benjamin Franklin   | It is hard for an empty bag to standupright        |

| Proverbs 15:1       | A soft answer turneth away wrath                    |

| William Shakespeare | But, soft! whatlight through yonder window breaks? |

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

3 rows in set (0.00 sec)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值