Skip to content

Instantly share code, notes, and snippets.

@jnunemaker
Created August 30, 2010 14:38
Show Gist options
  • Save jnunemaker/557497 to your computer and use it in GitHub Desktop.
Save jnunemaker/557497 to your computer and use it in GitHub Desktop.
# gem install sunspot_rails
class Foo
include MongoMapper::Document
include Sunspot::Rails::Searchable
key :title, String
searchable do
text :title
end
end
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment