module Elasticsearch::Model::MongoidExtensions::SCI::ClassMethods
Public Instance Methods
create_index!(options = {})
click to toggle source
# File lib/elasticsearch/model/mongoid_extensions/sci.rb, line 44 def create_index!(options = {}) res = Array(__elasticsearch__.create_index!(options)) descendants.each { |cls| res << cls.__elasticsearch__.create_index!(options) } res.compact end
document_type_template(proc)
click to toggle source
# File lib/elasticsearch/model/mongoid_extensions/sci.rb, line 17 def document_type_template(proc) @@document_type_template = proc document_type @@document_type_template.call(self) end
import(options = {}, &block)
click to toggle source
# File lib/elasticsearch/model/mongoid_extensions/sci.rb, line 61 def import(options = {}, &block) __elasticsearch__.import(options.merge(criteria: criteria.type(to_s)), &block).to_i + subclasses.sort_by(&:model_name).map { |cls| cls.import(options, &block) }.sum end
index_name_template(proc)
click to toggle source
# File lib/elasticsearch/model/mongoid_extensions/sci.rb, line 12 def index_name_template(proc) @@index_name_template = proc index_name @@index_name_template.call(self) end
inherited(descendant)
click to toggle source
Calls superclass method
# File lib/elasticsearch/model/mongoid_extensions/sci.rb, line 22 def inherited(descendant) super(descendant) descendant.instance_eval do include Elasticsearch::Model end # propagate index_name_template descendant.index_name @@index_name_template.call(descendant) if defined?(@@index_name_template) descendant.document_type @@document_type_template.call(descendant) if defined?(@@document_type_template) # propagate settings descendant.settings settings.to_hash # propagate mapping to all descendants mapping.instance_variable_get(:@mapping).each do |name, options| descendant.mapping do indexes(name, options) end end end
refresh_index!(options = {})
click to toggle source
# File lib/elasticsearch/model/mongoid_extensions/sci.rb, line 50 def refresh_index!(options = {}) res = Array(__elasticsearch__.refresh_index!(options)) descendants.each { |cls| res << cls.__elasticsearch__.refresh_index!(options) } res.compact end
search(query_or_payload, options = {})
click to toggle source
# File lib/elasticsearch/model/mongoid_extensions/sci.rb, line 56 def search(query_or_payload, options = {}) models = options.fetch :models, [self] + descendants Elasticsearch::Model.search(query_or_payload, models, options.except(:models)) end