Question

I'm using Sunspot and Kaminari for pagination. However, I'm seeing that the max results returned (even though there is more) is 30.

Here's my code:

Kaminari.paginate_array(search.results).page(params[:page]).per(10)

Please advise on how to return all results and paginate accordingly.

Was it helpful?

Solution

All results from Solr are paginated... By default, Sunspot requests the first 30 results from Solr. In your example, you're paginating the array of the first 30 results returned by Solr.

I find it easiest to just call paginate in the search blocks in my controllers...

@search = Sunspot.search(BlogPost) do
  # filters...
  paginate(page: params[:page], per_page: 10)
end

Then use Kaminari's paginate helper in my views...

<%= paginate @search.results %>

* you could use @search.hits if you don't want to load model instances


Alternatively, it looks like you can pass in :total_count as a keyword argument to Kaminari's paginate_array method. So this should work if you want to stick with the method you're using above...

Kaminari.paginate_array(search.results, total_count: search.total).page(params[:page]).per(10)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top