May
14
2009

Thinking sphinx and paginating find

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

26
27
28
29
30
31
32
33
34
35
   def self.create_from_results(results, page, limit, options)
#      collection = self.new(page, limit,
#        results[:total] || 0, results[:total_found] || 0
#      )
#      collection.results = results
#      Changing the stuff to work with paginating find
      PagingEnumerator.new(options[:per_page] || 20, results[:total_found] || 0, false, options[:page], 1) do |page|
        instances_from_matches(results[:matches], options)
      end      
    end

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

tags: ,
posted in sphinx by prateek

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

5 Comments to "Thinking sphinx and paginating find"

  1. dharin wrote:

    i don’t have collection.rb file in lib/thinking_sphinx. what should i do?
    i have checked other files but nor getting the method that you are talking about.

  2. prateek wrote:

    Hi Dharin

    May be you are using a different version. I checked again and I do have a collection.rb in lib/thinking_sphinx

  3. Dennis Martinez wrote:

    The changes in this post don’t work anymore with the latest versions of thinking-sphinx. The ‘collection.rb’ file was removed a few months ago (see GitHub commit). I’ll be tinkering with this, and if I find an easy solution I’ll let you know.

  4. prateek wrote:

    Hi Dennis,

    Thanks for the update. If you find a solution, please let me know and I will link to it from the post. I’ll try to checkout the new version and let you know if I find out a solution.

    Thanks,
    Prateek

  5. Bruce wrote:

    The changes in this post don’t work anymore with the latest versions of thinking-sphinx. The ‘collection.rb’ file was removed a few months ago (see GitHub commit). I’ll be tinkering with this, and if I find an easy solution I’ll let you know.

Leave Your Comment

 
Powered by Wordpress and MySQL. Theme by openark.org