Mysql相似文本搜索 [英] Mysql similar text search

查看:107
本文介绍了Mysql相似文本搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下的mysql表-

I have a mysql table like below-

------------
keyword_text
------------
Lego kit for kids
Lego kit only for kids
Lego kit kids

+more different text entry

如您所见,以上示例中的 keyword_text 都相似.我想找到与上述任何关键字匹配的所有关键字.例如,如果我搜索仅适用于儿童的 乐高玩具包 ,它将返回我所有这3个keyword_text.

As you can see, the keyword_text in above example are all similar. I want to find all those match for any of the above keywords. For example if I search for Lego kit only for kids , it will return me all of those 3 keyword_text.

Input:
Lego kit only for kids

Output:
Lego kit for kids
Lego kit only for kids
Lego kit kids

OR 

mysql resource to use with mysql_fetch_assoc

该表具有大约1M的条目,并且全文索引已添加到 keyword_text .是否有任何mysql查询可以做到这一点,或者是否有任何类似的方法可以使用PHP来快速地做到这一点?

The table has approximately 1M entry and full text index is added to keyword_text. Is there any mysql query to do that or any similar way to do it quickly using PHP?

感谢帮助

推荐答案

一种方法是查看搜索词与关键字列表之间的Levenshtein距离.例如,有一些安静的示例说明了如何在MySQL中实现这一点. 这里

One approach is to look at the Levenshtein Distance between the search term and the keyword list. There are quiet a few examples of how to implement this in MySQL, eg. HERE

由于目录如此之大,因此您需要首先考虑实施过滤器(可能基于"LIKE"查找),以免测量所有1M行的距离.

Because you have such a large catalogue, you will need to look at implementing a filter first (perhaps based on a 'LIKE' lookup) so that you are not measuring the distance for all 1M rows.

如果您按距离对结果进行排名,则应该能够根据与搜索的相关性对结果进行排序.

If you rank results by distance then you should be able to sort results by relevancy to the search.

这篇关于Mysql相似文本搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆