Solr (Sunspot), the maximum result is more than 30?

I use Solr through Sunspot for rails, but I can’t figure out how to return more than 30 results?

Let's say I have this block to search for:

posts = Post.search do keywords('something') end 

How would I establish that a spot should return all matches, not just 30?

+3
ruby-on-rails solr
source share
3 answers

You can use paginate :

 posts = Post.search do keywords 'something' paginate :page => 1, :per_page => 100 end 

To change the default number of results, add the following to application.rb or its own initialization file.

 Sunspot.config.pagination.default_per_page = 30 

A source

+15
source share

To clarify, Solr always paginates results - 30 is an arbitrary default value, but page length always exists. If you want to get all the results, you can set a very high page or page length based on the results of your code to make an array with all the results (the latter is probably preferable).

+5
source share

You can also change the configuration of SolR, as indicated here: http://solr.pl/en/2011/01/10/optimization-query-result-window-size/

+1
source share

All Articles