# Finding the most similar topics through tags

**URL:** <https://www.ruby-forum.com/t/finding-the-most-similar-topics-through-tags/144227>\
**Category:** Rails\
**Created:** [July 27, 2008, 1:22am UTC](https://www.ruby-forum.com/t/finding-the-most-similar-topics-through-tags/144227 "2008-07-27T01:22:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [July 27, 2008, 1:22am UTC](https://www.ruby-forum.com/t/finding-the-most-similar-topics-through-tags/144227/1 "2008-07-27T01:22:15Z")

</div>

I have posts, and those posts have tags. Now what i would like to do  
is find, for a given post, the most similar posts based on the tags  
they have. I’d like to retrieve a list with all the posts from all the  
tags that the given post has, ordered by the number of how many  
similar tags they (the post and the retrieved posts) have.

Can anybody give a hint for doing something like this?

---

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [July 27, 2008, 3:49pm UTC](https://www.ruby-forum.com/t/finding-the-most-similar-topics-through-tags/144227/2 "2008-07-27T15:49:07Z")

</div>

I’ve no idea, how you could directly query your tags  
and get those results. I think even to make areasonable  
decision on how “similar” two give words may be.  
If you want only the number of equal words, you could  
count them.

But I would strongly recommend using a good indexing  
& search engine to do this. I’ve just moved a project  
with acts\_as\_taggable from ferret to sphinx and found  
sphinx a wonderful tool for such things. Ordering results  
by relevance & weighting fields works out of the box.
