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.
Asked
Active
Viewed 859 times
1
-
2Is it possible for you to normalize the table? then you could sort like that.. – konsolenfreddy Mar 21 '11 at 20:46
-
please renormalize. this is not a good design. – Randy Mar 21 '11 at 21:04
2 Answers
3
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;

Michael McTiernan
- 5,153
- 2
- 25
- 16