views:

178

answers:

2

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  A: 

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.

joshli
so I should store the keywords in separate columns?
Mark
If you store them in seperate columns, the database would be slower and you would be able to use a LIKE query. If you use a just one column, you can use full text searches. Another solution is have individual rows for each keyword and this will be a faster method and easier to implement but it might be slower (this is what I would do).
joshli
+1  A: 

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

jspcal