Mar
21
2009

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

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

1
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).

posted in acts_as_taggable, ruby on rails, sphinx, thinking sphinx by prateek

Follow comments via the RSS Feed | Leave a comment | Trackback URL

5 Comments to "Ferret to Sphinx: Part 1 – Why and how to integrate it with acts_as_taggable"

  1. Thinking sphinx and paginating find | Muziboo Development Blog wrote:

    [...] Ferret to Sphinx: Part 1 – Why and how to integrate it with acts_as_taggable [...]

  2. Yves wrote:

    Sorry, but this does not work.

    class Service :category
    indexes title
    indexes description
    indexes user.login, :as => :provider
    indexes taggings.tag.name, :as => :tag_name

    end

    end

    Will lead to:

    ERROR: index ’service_core’: sql_range_query: Unknown column ’services.name’ in ‘field list’ (DSN=mysql://root:***@localhost:3306/app_development).

  3. prateek wrote:

    Yves .. are you using acts_as_taggable?

    Also the first line class Service :category does not look right to me. Let me know and I will try to help you out

    Thanks

  4. Matthyew Fritch wrote:

    This was helpful site.Thank you

  5. Thinking Sphinx and Acts_as_taggable_on_steroids « Ki o Tsuke. Rei! wrote:

    [...] thanks: http://devblog.muziboo.com/2009/03/21/ferret-to-sphinx-part-1-why-and-how-to-integrate-it-with-acts_... [...]

Leave Your Comment

 
Powered by Wordpress and MySQL. Theme by openark.org