Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you implement Related tags functionality as used in Stackoverflow.com?

Tags:

algorithm

How do you implement the 'related tags' functionality as used in many websites like our stackoverflow.com and http://tagexplorer.sandbox.yahoo.com/.

like image 642
Daksh Avatar asked Jan 14 '09 07:01

Daksh


2 Answers

My guess is that it is a correlation between which tags are most often used together.

For example:

  • Question A tagged with tag1, tag2
  • Question B tagged with tag1, tag3
  • Question C tagged with tag1, tag2

Then it's natural to assume that tag2 "is related to" tag1.

I would say the best place to learn would be O'Reilly's Programming Collective Intelligence book.

like image 54
Swaroop C H Avatar answered Nov 11 '22 07:11

Swaroop C H


A couple of ways come to mind. You could just do a quick query to select related tag names:

SELECT * FROM tags WHERE tag_name LIKE '%$current_tag%'

Another way would be to actually setup your tag table to have a relations field, maybe related IDs separated by commas, but this seems hellish to maintain.

I'm sure someone will come up with a better answer, so I'm quite curious as well.

like image 1
David Avatar answered Nov 11 '22 08:11

David