Skip to content

Instantly share code, notes, and snippets.

@jacqui
Created June 16, 2011 17:38
Show Gist options
  • Save jacqui/1029772 to your computer and use it in GitHub Desktop.
Save jacqui/1029772 to your computer and use it in GitHub Desktop.
require 'sunspot'
module SunspotAdapter
class InstanceAdapter < Sunspot::Adapters::InstanceAdapter
def id
@instance.id
end
end
class DataAccessor < Sunspot::Adapters::DataAccessor
def load(id)
Team.find(BSON::ObjectId.from_string(id))
end
def load_all(ids)
Team.where(:_id.in => ids.map{|id| BSON::ObjectId.from_string(id)})
end
end
end
require 'sunspot'
module SunspotAdapter
class InstanceAdapter < Sunspot::Adapters::InstanceAdapter
def id
@instance.id
end
end
class DataAccessor < Sunspot::Adapters::DataAccessor
def load(id)
@klass.find(BSON::ObjectId.from_string(id))
end
def load_all(ids)
@klass.where(:_id.in => ids.map{|id| BSON::ObjectId.from_string(id)})
end
end
end
require 'sunspot'
require 'sunspot_adapter'
Sunspot::Adapters::InstanceAdapter.register(SunspotAdapter::InstanceAdapter, Team)
Sunspot::Adapters::DataAccessor.register(SunspotAdapter::DataAccessor, Team)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment