问题
I am looking to implement a 'youtube related videos' style related content system.
I have 5 tags/keywords for each of my pages, a title and a description. I would like to display links to the two most similar pages.
I am guessing a mysql query based around order by relevance.
many thanks.
回答1:
you can break up the title, description, keywords into tokens and then do a full text search in mysql on those keywords and order by relevance.
select * from article where match(title, description, keywords)
against ('word1 word2 word3 word4' in boolean mode)
order by relevance desc
http://dev.mysql.com/doc/refman/5.0/en/fulltext-boolean.html
回答2:
First, the keywords should be indexed so that it can be accessed faster.
Then you can do a fulltext search: http://en.wikipedia.org/wiki/Full_text_search Or, you could do a LIKE query: http://www.w3schools.com/SQL/sql_like.asp
Then, with those results, you just make the list of the related items.
来源:https://stackoverflow.com/questions/2039240/php-display-links-to-related-content