php - display links to related content

◇◆丶佛笑我妖孽 提交于 2019-12-08 10:40:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!