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

Posted by kLeos on Stack Overflow See other posts from Stack Overflow or by kLeos
Published on 2012-12-12T17:58:40Z Indexed on 2012/12/12 23:04 UTC
Read the original article Hit count: 261

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?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about search