Main module containing the search infrastructure for ActiveModel classes.
By including this module, you'll provide the model with facilities to perform searches against index, define index settings and mappings, access the index object, etc.
All the Tire methods are accessible via the "proxy" class and instance methods of the model, named `tire`, eg. `Article.tire.search 'foo'`.
When there's no clash with a method in the class (your own, defined by another gem, etc) Tire will bring these methods to the top-level namespace of the class, eg. `Article.search 'foo'`.
You'll find the relevant methods in the ClassMethods and InstanceMethods module.
A hook triggered by the `include Tire::Model::Search` statement in the model.
# File lib/tire/model/search.rb, line 258 def self.included(base) base.class_eval do # Returns proxy to the _Tire's_ class methods. # def self.tire &block @__tire__ ||= ClassMethodsProxy.new(self) @__tire__.instance_eval(&block) if block_given? @__tire__ end # Returns proxy to the _Tire's_ instance methods. # def tire &block @__tire__ ||= InstanceMethodsProxy.new(self) @__tire__.instance_eval(&block) if block_given? @__tire__ end # Define _Tire's_ callbacks (<after|before>_update_elasticsearch_index). # define_model_callbacks(:update_elasticsearch_index, :only => [:after, :before]) if respond_to?(:define_model_callbacks) # Serialize the model as a Hash. # # Uses `serializable_hash` representation of the model, # unless implemented in the model already. # def to_hash self.serializable_hash end unless instance_methods.map(&:to_sym).include?(:to_hash) end # Alias _Tire's_ class methods in the top-level namespace of the model, # unless there's a conflict with existing method. # ClassMethodsProxy::INTERFACE.each do |method| base.class_eval " def self.#{method}(*args, &block) # def search(*args, &block) tire.__send__(#{method.inspect}, *args, &block) # tire.__send__(:search, *args, &block) end # end ", __FILE__, __LINE__ unless base.public_methods.map(&:to_sym).include?(method.to_sym) end # Alias _Tire's_ instance methods in the top-level namespace of the model, # unless there's a conflict with existing method InstanceMethodsProxy::INTERFACE.each do |method| base.class_eval " def #{method}(*args, &block) # def to_indexed_json(*args, &block) tire.__send__(#{method.inspect}, *args, &block) # tire.__send__(:to_indexed_json, *args, &block) end # end ", __FILE__, __LINE__ unless base.instance_methods.map(&:to_sym).include?(method.to_sym) end # Include the `load` functionality in Results::Item # Results::Item.send :include, Loader end
Alias for Tire::Model::Naming::ClassMethods#index_prefix
# File lib/tire/model/search.rb, line 24 def self.index_prefix(*args) Naming::ClassMethods.index_prefix(*args) end
Returns proxy to the _Tire's_ class methods.
# File lib/tire/model/search.rb, line 263 def self.tire &block @__tire__ ||= ClassMethodsProxy.new(self) @__tire__.instance_eval(&block) if block_given? @__tire__ end
Returns proxy to the _Tire's_ instance methods.
# File lib/tire/model/search.rb, line 272 def tire &block @__tire__ ||= InstanceMethodsProxy.new(self) @__tire__.instance_eval(&block) if block_given? @__tire__ end
Serialize the model as a Hash.
Uses `serializable_hash` representation of the model, unless implemented in the model already.
# File lib/tire/model/search.rb, line 289 def to_hash self.serializable_hash end