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?
Rather than adjusting params, just add a line:
order_by :random
rows :2
See here: http://wiki.apache.org/solr/CommonQueryParameters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With