Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails solr search limit total search results / get fixed number of results

I'm trying to perform a search, order the results randomly, and only return a number of results, not all matches. Something like limit(2) I've tried using the Solr param 'rows' but that doesn't seem to do anything:

@featured_articles = Article.search do 
  with(:is_featured, true)
  order_by :random
  adjust_solr_params do |params|
    params[:rows] = 2
  end
end

@featured_articles.total should be 2, but it returns more than 2

How can I get a randomized fixed number of results?

like image 522
gt565k Avatar asked Nov 13 '22 15:11

gt565k


1 Answers

Rather than adjusting params, just add a line:

order_by :random
rows :2

See here: http://wiki.apache.org/solr/CommonQueryParameters

like image 114
Ryan Clark Avatar answered Nov 15 '22 08:11

Ryan Clark