Class: AgnosticBackend::Cloudsearch::Indexer
- Inherits:
-
Indexer
- Object
- Indexer
- AgnosticBackend::Cloudsearch::Indexer
show all
- Includes:
- Utilities
- Defined in:
- lib/agnostic_backend/cloudsearch/indexer.rb
Constant Summary
collapse
- MAX_PAYLOAD_SIZE_IN_BYTES =
4_500_000
Instance Attribute Summary
Attributes inherited from Indexer
#index
Instance Method Summary
collapse
Methods included from Utilities
included
Methods inherited from Indexer
#generate_document, #initialize, #put, #put_all
Instance Method Details
#delete(document_id) ⇒ Object
13
14
15
|
# File 'lib/agnostic_backend/cloudsearch/indexer.rb', line 13
def delete(document_id)
delete_all([document_id])
end
|
#delete_all(document_ids) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/agnostic_backend/cloudsearch/indexer.rb', line 17
def delete_all(document_ids)
documents = document_ids.map do |document_id|
{"type" => 'delete',
"id" => document_id}
end
publish_all(documents)
end
|
#publish(document) ⇒ Object
26
27
28
|
# File 'lib/agnostic_backend/cloudsearch/indexer.rb', line 26
def publish(document)
publish_all([document])
end
|
#publish_all(documents) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/agnostic_backend/cloudsearch/indexer.rb', line 30
def publish_all(documents)
return if documents.empty?
payload = ActiveSupport::JSON.encode(documents)
raise PayloadLimitExceededError.new if payload_too_heavy? payload
with_exponential_backoff Aws::CloudSearch::Errors::Throttling do
client.upload_documents(
documents: payload,
content_type:'application/json'
)
end
end
|