Module: Elasticsearch::Model::MongoidExtensions::SCI::ClassMethods
- Defined in:
- lib/elasticsearch/model/mongoid_extensions/sci.rb
Instance Method Summary collapse
- #create_index!(options = {}) ⇒ Object
- #document_type_template(proc) ⇒ Object
- #import(options = {}, &block) ⇒ Object
- #index_name_template(proc) ⇒ Object
- #inherited(descendant) ⇒ Object
- #refresh_index!(options = {}) ⇒ Object
- #search(query_or_payload, options = {}) ⇒ Object
Instance Method Details
#create_index!(options = {}) ⇒ Object
44 45 46 47 48 |
# File 'lib/elasticsearch/model/mongoid_extensions/sci.rb', line 44 def create_index!( = {}) res = Array(__elasticsearch__.create_index!()) descendants.each { |cls| res << cls.__elasticsearch__.create_index!() } res.compact end |
#document_type_template(proc) ⇒ Object
17 18 19 20 |
# 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) ⇒ Object
61 62 63 64 |
# File 'lib/elasticsearch/model/mongoid_extensions/sci.rb', line 61 def import( = {}, &block) __elasticsearch__.import(.merge(criteria: criteria.type(to_s)), &block).to_i + subclasses.sort_by(&:model_name).map { |cls| cls.import(, &block) }.sum end |
#index_name_template(proc) ⇒ Object
12 13 14 15 |
# 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) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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, | descendant.mapping do indexes(name, ) end end end |
#refresh_index!(options = {}) ⇒ Object
50 51 52 53 54 |
# File 'lib/elasticsearch/model/mongoid_extensions/sci.rb', line 50 def refresh_index!( = {}) res = Array(__elasticsearch__.refresh_index!()) descendants.each { |cls| res << cls.__elasticsearch__.refresh_index!() } res.compact end |
#search(query_or_payload, options = {}) ⇒ Object
56 57 58 59 |
# File 'lib/elasticsearch/model/mongoid_extensions/sci.rb', line 56 def search(query_or_payload, = {}) models = .fetch :models, [self] + descendants Elasticsearch::Model.search(query_or_payload, models, .except(:models)) end |