Module: BigIndex::Resource

Defined in:
lib/big_index/resource.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(model) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/big_index/resource.rb', line 5

def self.included(model)
  model.extend ClassMethods if defined?(ClassMethods)
  model.const_set('Resource', self) unless model.const_defined?('Resource')

  model.class_eval do
    include InstanceMethods

    @indexed = true

    @index_configuration = {
      :fields => [],
      :additional_fields => nil,
      :exclude_fields => [],
      :auto_save => true,
      :auto_commit => true,
      :background => true,
      :include => nil,
      :facets => nil,
      :boost => nil,
      :if => "true",
      :type_field => model.index_adapter.default_type_field,
      :primary_key_field => model.index_adapter.default_primary_key_field,
      :default_boost => 1.0
    }

    after_save    :index_save
    after_destroy :index_destroy

    def self.inherited(child)
      child.index_configuration = self.index_configuration
    end

    class << self
      # Defines find_with_index() and find_without_index()
      alias_method_chain :find, :index
    end
  end
end