7

I recently decided to port my indexing engine from sphinx to solr. Having used kaminari with thinking_sphinx I decided to try making use of generic pagination in sunspot https://github.com/sunspot/sunspot/pull/64 / https://github.com/sunspot/sunspot/pull/67, in order to use avoid moving to will_paginate.

My search is handled as follows:

@search = Address.search do
  fulltext params[:search]
  with(:updated_at).greater_than(1.week.ago)
  order_by :updated_at, :desc
  paginate :page => params[:page], :per_page => 7
end

My view is unchanged from what I had when I was using thinking_sphinx:

<%= render :partial => 'address' %>
<%= paginate @addresses %>

My problem is that after the change I continually get the following error when trying to perform a search:

undefined method `current_page' for []:Array

I am using the latest version of sunspot, which to my knowledge should enable me to use kaminari:

Using sunspot (1.3.0.rc3) from git://github.com/sunspot/sunspot.git (at master) 
Using sunspot_rails (1.3.0.rc3) from git://github.com/sunspot/sunspot.git (at master) 

This worked perfectly with my old thinking_sphinx setup, so what am I doing wrong?

maecro
  • 233
  • 2
  • 9
  • Well I got tired of trying to make it work and switched to will_paginate, works great now. – maecro Oct 28 '11 at 13:12
  • 2
    there is a sunspot kaminari gem which makes kaminari and sunspot play nicely together [https://github.com/richardiux/sunspot_with_kaminari](https://github.com/richardiux/sunspot_with_kaminari) works absolutely fine for us. – Marian Theisen Oct 28 '11 at 16:01
  • I had seen that gem but overlooked at the time as there did not seem to be a lot of activity there. Perhaps I judged it somewhat harshly, I will take another look at it. Cheers for the recommendation. – maecro Oct 29 '11 at 10:42
  • if you look at the code, you can see, that it really is just a few lines of code, very simple, and if breaks with a future kaminari or sunspot version, it should be dead easy to fork and fix. – Marian Theisen Oct 29 '11 at 11:01

1 Answers1

13

This is how I have used and it works great

@search = Sunspot.search(Listing) do
      if params[:category].present?
        with :category_id, params[:category]
      end
      if params[:subcategory].present?
        with :subcategory_id, params[:subcategory]
      end
      if params[:q].present?
        keywords params[:q]  do 
          fields :title, :description
        end
      end
      paginate :page => params[:page], :per_page => SEARCH_RESULT_PER_PAGE
    end

And in views I have this

<%= paginate @search.hits %>
DeathHammer
  • 650
  • 6
  • 11