Ferret to Sphinx: Part 1 - Why and how to integrate it with acts_as_taggable

This post was migrated over from Muziboo DevBlog. I am currently working on moving Muziboo's search from ferret to sphinx. We were using acts_as_ferret (AAF) plugin which provides a very simple rails integration with ferret. AAF binds itself to the active record callbacks and makes index updation painless. However AAF is pretty unstable in production mode and we realized this only lately with increasing traffic. We often had corrupted indexes and page errors as a result of that (since ferret is almost deeply integrated into models, it breaks a lot of functionality apart from search when something goes wrong). Also another problem with ferret is the high memory usage and the fact that with multiple mongrels, you will have to run a drb process to make sure the index is not written by multiple processes and corrupted. On looking for alternatives, I found out about Thinking Sphinx, a plugin that makes it easy to use sphinx in your rails project. There is some documentation to get you started with TS once you decide to use it and also a peepcode pdf which has some good info. I could get the basic search functionality up and running in no time but had to spend sometime getting some integration going with other plugins. I will detail some of those things in this and next few posts. Acts as taggable helps you in tagging your objects and we wanted sphinx to search on the tags too. It turns out that its very simple. All you have to say in your define_index block is
indexes taggings.tag.name,  :as=>tag_name
Just make sure that you restart sphinx and reindex your data before after adding this in your model(s).

blog comments powered by Disqus
Hana Mohan
Hana Mohan