rails solr limit number of results returned by search

301 views
Skip to first unread message

yaki...@gmail.com

unread,
Dec 12, 2012, 12:30:40 PM12/12/12
to ruby-s...@googlegroups.com
I'm trying to basically search my rails objects, order by random and only return 2 of the results

but it seems that when I use 

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

@featured_results.total is not equal to 2, but is greater than 2

How do I limit the results returned by solr?


Tom Cocca

unread,
Dec 12, 2012, 12:38:31 PM12/12/12
to ruby-sunspot
Try paginate(:per_page => 2) after your order_by :random and remove
the adjust_solr_params part of that search.

Should give you 2 results.

~ Tom
> --
> You received this message because you are subscribed to the Google Groups
> "Sunspot" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/ruby-sunspot/-/N_e_QPETQe4J.
> To post to this group, send email to ruby-s...@googlegroups.com.
> To unsubscribe from this group, send email to
> ruby-sunspot...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/ruby-sunspot?hl=en.
Reply all
Reply to author
Forward
0 new messages