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
def load_all(ids)
@clazz.all(:id => ids)
end
def find_all(options)
if options[:batch_size]
offset = 0
record_count = @clazz.count
while(offset < record_count)
yield @clazz.all(:limit => options[:batch_size], :skip => offset)
offset += options[:batch_size]
end
else
yield @clazz.all
end
end
end
end
Sunspot::Adapters::DataAccessor.register(MongoAdapter::DataAccessor, MongoMapper::Document)
Sunspot::Adapters::InstanceAdapter.register(MongoAdapter::InstanceAdapter, MongoMapper::Document)