at the moment I’m doing a Select from multiple tables using Sunspot. I’m limiting the records selected with the condition that the creation date must have been within the past 5 days. However I would like to take this further and limit the number of records selected to say, 20? Is there any way to do this with sunspot? I’m not doing any fancy groupings or anything. Simply selecting records belonging to various models and displaying them onto the screen.
My current code:
@updates = Sunspot.search(Upload,Help, User...) do
with(:created_at).greater_than(5.days.ago)
order_by(:created_at, :desc)
end
I tried adding the ‘limit’ clause as specified by the readme on Github but that produced an undefined method error probably because I’m doing a global Sunspot search as opposed to a search on a specific model.
Error code:
@updates = Sunspot.search(Upload,Help, User...) do
with(:created_at).greater_than(5.days.ago)
order_by(:created_at, :desc)
limit(20)
end
Error message:
undefined method `limit' for #<Sunspot::DSL::Search:0x0000000790b8c8>
The “limit” method is for “groups”. See the readme section on groups. Sunspot provides pagination (and works like a charm with the kaminari gem btw). See the section on solr pagination in the readme. Specifically, try this: