How can I implement a ‘related items’ feature for posts in a blog? I would like to return a list of similar posts based on analysis of post titles.
My own ideas for doing this seem very inefficient and I wonder if there are tools that already support this functionality. I didn’t find any help via google, ruby toolbox, and I looked at sunspot api. How would you achieve this in your blog application/content site?
Update
For those interested in this functionality, I decided to go with sunspot which allows me to use this in my show action:
@find_related = Post.search do
fulltext params[:title]
end
This returns an array of related posts:
@related = @find_related.results
Thanks for all the feedback and this railscast was a big help
Sure there are some good and efficient tools for that! Technically, what you want is a full text search on an indexed database of post titles/other data. We have tools that run external database that handles all the searching and indexing. Those backends are universal and not in ruby, you only use client logic in your app. That’s very efficient, as you probably won’t be able to implement any other algorithms than existing ones. I would recommend the following:
These libraries provide client logic for data exchange with above mentioned search engines (all are from Apache foundation)