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!
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.
Link | October 9th, 2009 at 11:28 am
Hi Dharin
May be you are using a different version. I checked again and I do have a collection.rb in lib/thinking_sphinx
Link | October 9th, 2009 at 2:41 pm
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.
Link | January 15th, 2010 at 9:29 pm
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
Link | January 16th, 2010 at 10:20 am
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.
Link | May 19th, 2010 at 2:19 pm