Created
August 30, 2010 14:38
-
-
Save jnunemaker/557497 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gem install sunspot_rails | |
class Foo | |
include MongoMapper::Document | |
include Sunspot::Rails::Searchable | |
key :title, String | |
searchable do | |
text :title | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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