Created
May 9, 2015 14:38
-
-
Save stackdump/0e5b3a2764cffa535116 to your computer and use it in GitHub Desktop.
# NOTE: This is a modified version of : # https://github.com/derekharmel/sunspot_mongo/blob/e5024476fd71f9c10c39884b9b50879929480ddc/lib/sunspot/mongo.rb
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
# == Examples: | |
# | |
# class Post < ActiveRecord::Base | |
# | |
# include Sunspot::Document | |
# | |
# searchable do | |
# text :title | |
# end | |
# end | |
# | |
module Sunspot | |
module Document | |
def self.included(base) | |
base.class_eval do | |
extend Sunspot::Rails::Searchable::ActsAsMethods | |
Sunspot::Adapters::DataAccessor.register(DataAccessor, base) | |
Sunspot::Adapters::InstanceAdapter.register(InstanceAdapter, base) | |
end | |
end | |
class InstanceAdapter < Sunspot::Adapters::InstanceAdapter | |
def id | |
@instance.id | |
end | |
end | |
class DataAccessor < Sunspot::Adapters::DataAccessor | |
def load(id) | |
criteria(id).first | |
end | |
def load_all(ids) | |
criteria(ids) | |
end | |
private | |
def criteria(id) | |
@clazz.find(id) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment