Thinking sphinx and paginating find

This post was migrated over from Muziboo DevBlog. I wrote sometime back about moving from ferret to sphinx and decided to write the second part of the post today. At Muziboo, we use the paginating find plugin to paginate results. You can find a great tutorial on paginating find at Ilya's blog. Thinking sphinx however works only with will paginate plugin (atleast out of the box) and needs to be patched to work with paginating_find.

Fortunately, the change is very simple. You need to edit the file lib/thinking_sphinx/collection.rb and comment out the existing code in the function self.create_from_results and add stuff for paginating find. In the end this is how the function looks

   def self.create_from_results(results, page, limit, options)
#      collection =, limit,
#        results[:total] || 0, results[:total_found] || 0
#      )
#      collection.results = results
#      Changing the stuff to work with paginating find[:per_page] || 20, results[:total_found] || 0, false, options[:page], 1) do |page|
        instances_from_matches(results[:matches], options)

Make the change and restart your mongrel and you are ready to go!

blog comments powered by Disqus
Hana Mohan
Hana Mohan