Skip to content

Instantly share code, notes, and snippets.

@aermolaev
Created September 30, 2010 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aermolaev/604581 to your computer and use it in GitHub Desktop.
Save aermolaev/604581 to your computer and use it in GitHub Desktop.
paginate_search в ferret
module ActsAsFerret
class SearchResults
# To prevent WillPaginate warning
attr_reader :total_pages
end
module ClassMethods
def paginate_search(query, options = {}, find_options = {})
page, per_page = wp_parse_options(options)
offset = (page.to_i - 1) * per_page
hits = total_hits(query)
hits = 1 if hits == 0
f_options = find_options.merge(:offset => offset, :limit => per_page)
result = find_with_ferret(query, { :offset => 0, :limit => hits }, f_options)
WillPaginate::Collection.new(page, per_page, result.total_hits).tap do |pager|
pager.replace(result)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment