I am trying to figure out how to arrange items with matching tags by the number of tags that match.
Let's say you have three MySQL tables:
tags(tag_id, title)articles(article_id, some_text)articles_tags(tag_id, article_id)
Now let's say you have four articles where:
article_id = 1 has the tags "humor", "funny" and "funny".
article_id = 2 has the tags "funny", "dumb" and "dumb".
article_id = 3 has the tags "funny", "dumb" and "dumb".
article_id = 4 has the tag "completely serious".
You need to find all the articles associated with article_id = 2 with at least one matching tag and return the results in the order of best matches. In other words, article_id = 3 should be the first, and article_id = 1 second, and article_id = 4 should not be displayed at all.
Is this something that can be done in SQL queries or alone, or is it better suited for something like Sphinx? If the first, what query should be made and what indexes should be created for the most effective results? If the latter, please expand.
mysql search tags sphinx
Josh smith
source share