Class: AWSCloudSearch::DocumentBatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_cloud_search/document_batcher.rb

Overview

Convenience method that will allow continuous batch additions and will chunk to a size threshold and send requests for each chunk.

Instance Method Summary collapse

Constructor Details

#initialize(cs) ⇒ DocumentBatcher

Returns a new instance of DocumentBatcher


9
10
11
12
# File 'lib/aws_cloud_search/document_batcher.rb', line 9

def initialize(cs)
  @cs = cs
  @batch = DocumentBatch.new
end

Instance Method Details

#add_document(doc) ⇒ Object


14
15
16
17
18
# File 'lib/aws_cloud_search/document_batcher.rb', line 14

def add_document(doc)
  flush if @batch.full?

  @batch.add_document doc
end

#delete_document(doc) ⇒ Object


20
21
22
23
24
# File 'lib/aws_cloud_search/document_batcher.rb', line 20

def delete_document(doc)
  flush if @batch.full?

  @batch.delete_document doc
end

#flushObject

Sends the batch of adds and deletes to CloudSearch Search and then clears the current batch. TODO: (dj) implement connection retry logic


28
29
30
31
32
# File 'lib/aws_cloud_search/document_batcher.rb', line 28

def flush
  return true if @batch.empty?
  @cs.documents_batch @batch
  @batch.clear
end