Skip to content

Instantly share code, notes, and snippets.

@shanna
Created December 16, 2008 00:41
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 shanna/36196 to your computer and use it in GitHub Desktop.
Save shanna/36196 to your computer and use it in GitHub Desktop.
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