This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/vendor/plugins/sunspot_mongoid/lib/sunspot/mongoid.rb

50 lines
911 B
Ruby
Raw Normal View History

require 'sunspot'
require 'mongoid'
require 'sunspot/rails'
# == Examples:
#
# class Post
# include Mongoid::Document
# field :title
#
# include Sunspot::Mongoid
# searchable do
# text :title
# end
# end
#
module Sunspot
module Mongoid
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.criteria.id(id)
end
end
end
end