How to create a tag system like stackoverflow

I am implementing a tag system similar to the StackOverflow tag system, but I'm just wondering how to get the related tags and determine the relationship of weights between the tags, for example, the "Related Tags" list on any tag page, such as https://stackoverflow.com/a/12690/. .. they determine the weight of the relationship by matching between two or more tags

How can I do this in PHP / MySQl to determine the most related tags for the "X" tag and update all weights as users add more and more posts / questions?

+6
php mysql tags database-design tagging
source share
3 answers

You probably want to look at the statistics:

  • tagged with X
  • check all other Y tags
  • count how often Y and X appear at the same time
  • divide how often Y appears
  • ???
  • Profit !!!

As for more information about step 5: this information changes very slowly, so you can cache this material and update it only when you have time.

In the end, what you want is attitude

conditional_probability(X, Y, P) 

Which tells you how likely the (P) tag is Y if X. P was calculated in step 4.

+2
source share

I used this blog post to calculate the relative tag size in the cloud . You can use this algorithm for all possible or specific set found.

Instead of storing denormalized weights for all tags in the database, I cache them in my (Ruby) process and rebuild them when tags are added / removed or when the process is restarted.

How to save them, you usually want:

  • A tag table that associates unique tag names with line identifiers, and
  • The tags_items table provides you with an n-to-n mapping between tags and elements.

After that, and as soon as you have the set of elements found on the results page, this is a simple connection and unique to recognize a set of related tags.

+1
source share

1 Each message identifier can be tagged with one or more tags (PHP + other tags)

2 Coming back just like every tag has an associated post id

3 Foreach post id gets all tags other than PHP

4 Show only those that have a score greater than a number (e.g. 4000)

Think about it, this question has been tagged "Mysql" "Database-design" "Tags" and "Tagging". You see how you linked PHP with other tags.

0
source share

All Articles