Created
September 30, 2010 13:39
-
-
Save aermolaev/604581 to your computer and use it in GitHub Desktop.
paginate_search в ferret
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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