Module: Elasticsearch::Model::Adapter::Lycra::Document::Importing

Defined in:
lib/elasticsearch/model/adapters/lycra/document.rb

Instance Method Summary collapse

Instance Method Details

#__find_in_batches(options = {}, &block) ⇒ Object

Fetch batches of records from the database (used by the import method)



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/elasticsearch/model/adapters/lycra/document.rb', line 83

def __find_in_batches(options={}, &block)
  query = options.delete(:query)
  named_scope = options.delete(:scope)
  preprocess = options.delete(:preprocess)

  scope = subject_type
  scope = scope.__send__(named_scope) if named_scope
  scope = scope.instance_exec(&query) if query

  scope.find_in_batches(options) do |batch|
    yield (preprocess ? self.__send__(preprocess, batch) : batch)
  end
end

#__transformObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/elasticsearch/model/adapters/lycra/document.rb', line 97

def __transform
  lambda do |model|
    json_data = begin
      if model.respond_to?(:model_document)
        # TODO model_document.as_indexed_json(model)
      else
        modoc = begin
          "#{model.class.name}Document".constantize
        rescue NameError => e
          raise "Unable to locate a document class for the #{model.class.name} model"
        end
        modoc.as_indexed_json(model)
      end
    end

    { index: { _id: model.id, data: json_data } }
  end
end