Skip to content

Instantly share code, notes, and snippets.

@dacort
Created January 26, 2010 20:29
Show Gist options
  • Save dacort/287191 to your computer and use it in GitHub Desktop.
Save dacort/287191 to your computer and use it in GitHub Desktop.
# Hook our MongoMapper model into Solr
module MongoAdapter
class InstanceAdapter < Sunspot::Adapters::InstanceAdapter
def id
@instance.id
end
end
class DataAccessor < Sunspot::Adapters::DataAccessor
def load(id)
@clazz.find(id)
end
end
end
Sunspot::Adapters::DataAccessor.register(MongoAdapter::DataAccessor, User)
Sunspot::Adapters::InstanceAdapter.register(MongoAdapter::InstanceAdapter, User)
Sunspot.setup(User) do
text :name
text :screen_name
text :description
string :screen_name
string :flists, :multiple => true do
listed_on.map{|l| l.keys.first.downcase.split(/-|_|\//)}.flatten
end
dynamic_text :lists do
count = 0
listed_on.inject({}) do |hash, l|
hash["#{count}_#{l.keys.first}".to_sym] = {
:value => l.keys.first,
:boost => l.values.first == 0 ? 1 : l.values.first
}
count += 1
hash
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment