mysql中的词相似性/相似性 [英] word likeness/similarity in mysql

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

问题描述

我有一个专栏,可以保存电影的类型(最多三个以斜杠分隔的说明符),例如喜剧/浪漫/冒险。在mysql或php中是否有一个函数或类似的东西可以让我采用电影的流派,并将它与其他行的其他流派进行比较并按照相似性排列它们?例如,制作一部带有喜剧/浪漫/冒险的电影将会首先将所有三部电影返回到电影中,然后再将电影与其中两种风格的电影结合在一起,最后可能会有这些风格中的一种。

解决方案

如果您启用全文索引,你可以做到。尽管如此,我建议使用外部全文搜索引擎(如sphinx)来处理这个问题,因为MySQL内置的全文索引确实不是很好。



你会开始在类型字段上设置一个全文索引

ALTER TABLE movies ADD FULLTEXT INDEX(genre); $ b $ p
$ b

然后你就可以从中选择:

 选择*,匹配(流派)反对('喜剧浪漫冒险')与电影的相关性ORDER BY相关性DESC; 


I have a column that holds the genre of a movie (up to three specifiers separated by slashes) such as "comedy/romance/adventure." Is there a function or something similar in mysql or php that would allow me to take the genre of a movie and compare it with other genres of other rows and arrange them by likeness? For example, having a movie with "comedy/romance/adventure" would return movies with all three first, and then movies with 2 of those genres, and finally movies with maybe 1 of those genres.

解决方案

If you enable full-text indexing on the genre column, you can do it. I would recommend using an external full-text search engine such as sphinx to handle this, though, as MySQL's built-in full-text indexing really ain't that great.

You'd start by setting a full-text index on the genre field

ALTER TABLE movies ADD FULLTEXT INDEX (genre);

Then you'd be able to select from this like so:

SELECT *, MATCH(genre) AGAINST ('comedy romance adventure') AS relevancy FROM movies ORDER BY relevancy DESC;

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

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