Class: Esse::AsyncIndexing::Actions::UpsertDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/esse/async_indexing/actions/upsert_document.rb

Constant Summary collapse

DOC_ARGS =
%i[lazy_attributes]

Class Method Summary collapse

Class Method Details

.call(index_class_name, repo_name, document_id, operation = "index", options = {}) ⇒ Object

OPERATIONS = %w[index update delete]



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/esse/async_indexing/actions/upsert_document.rb', line 8

def self.call(index_class_name, repo_name, document_id, operation = "index", options = {})
  case operation
  when "delete"
    DeleteDocument.call(index_class_name, repo_name, document_id, options)
  when "update"
    result = UpdateDocument.call(index_class_name, repo_name, document_id, options)
    return result if result != :not_found
    DeleteDocument.call(index_class_name, repo_name, document_id, options)
  when "index"
    result = IndexDocument.call(index_class_name, repo_name, document_id, options)
    return result if result != :not_found
    DeleteDocument.call(index_class_name, repo_name, document_id, options)
  else
    raise ArgumentError, "operation must be one of index, update, delete"
  end
end