Created
December 16, 2008 00:41
-
-
Save shanna/36196 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 | |
property :id, Serial | |
property :name, String | |
# No dm-is-searchable, we need to order by :weight. | |
def self.my_search(search_options = {}, options = {}) | |
docs = repository(:search){self.all(search_options)} | |
ids = docs.map{|doc| doc[:id]} | |
results = self.all(options.merge(:id => ids)) | |
# Sort by the ids which are ordered by :weight in the first place. | |
results.sort{|a, b| ids.index(a.id) <=> ids.index(b.id)} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment