Created
March 10, 2009 04:54
-
-
Save shanna/76741 to your computer and use it in GitHub Desktop.
This file contains 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 Blah | |
include DataMapper::SphinxResource | |
# repository(:default) properties | |
# repository(:search) sphinx properties | |
#-- | |
# Pagination provided by dm-is-paginated | |
# http://github.com/lholden/dm-is-paginated/tree | |
# You could just as easily brew the pagination yourself, it's very simple: | |
# http://github.com/lholden/dm-is-paginated/blob/670509c97d6fe298d2314dafbe1db91eff759ee5/lib/dm-is-paginated/is/paginated.rb | |
def self.search(options) | |
page = options.delete(:page) || 1 | |
per_page = options.delete(:per_page) || 5 | |
# Search sphinx. This is an all search since we need the total for the page_count. | |
docs = repository(:search){ self.all(options) } | |
ids = docs.map{|doc| doc[:id]} | |
page_count = (ids.size.to_f / per_page).ceil | |
[page_count, all(:id => ids, :limit => per_page, :offset => (page - 1) * per_page)] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment