Reputation: 27
I'm trying to paginate the result from thinking sphinx in rails console without any pagination gem. Is it possible to do?
Upvotes: 0
Views: 509
Reputation: 16226
Yes, it is possible. Thinking Sphinx does not require any pagination gems… you can either use the :per_page
and :page
options in a search request:
# page: the page of results, defaults to 1 (the first page).
# per_page: number of results in each set, defaults to 20.
Article.search "pancakes", :page => 2, :per_page => 50
These are the same options as WillPaginate - and the resulting search results object can be used with the WillPaginate view helper - but you do not need WillPaginate to use these options.
There is also the possibility to use the per_page
method on a search results object, like with Kaminari - but again, Kaminari is not required (even though the search results object can also be used with Kaminari's view helper):
articles = Article.search("pancakes")
articles.per_page(10)
There is also the :offset
option, if you wish to calculate the number of results to skip (rather than using :page
and :per_page
to automate such calculations).
Upvotes: 1