Class: JayAPI::Elasticsearch::BatchCounter

Inherits:
Object
  • Object
show all
Defined in:
lib/jay_api/elasticsearch/batch_counter.rb

Overview

Manages and tracks the current batch within the QueryResults context. This class is responsible for keeping track of the current batch start position and calculating the start position for the next batch based on the batch size.

Constant Summary collapse

DEFAULT_START =

The start of the batch to default to, if no other information is provided.

0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#batch_sizeInteger (readonly)

Returns The size of each batch as determined by the query or the default size.

Returns:

  • (Integer)

    The size of each batch as determined by the query or the default size



21
22
23
# File 'lib/jay_api/elasticsearch/batch_counter.rb', line 21

def batch_size
  @batch_size
end

#start_currentInteger (readonly)

Returns The starting index of the current batch.

Returns:

  • (Integer)

    The starting index of the current batch



21
# File 'lib/jay_api/elasticsearch/batch_counter.rb', line 21

attr_reader :batch_size, :start_current, :start_next

#start_nextObject (readonly)

Returns the value of attribute start_next.



21
# File 'lib/jay_api/elasticsearch/batch_counter.rb', line 21

attr_reader :batch_size, :start_current, :start_next

Class Method Details

.create_or_update(batch, query, size) ⇒ BatchCounter

Creates a new BatchCounter object by either updating a copy of the batch instance with new values or creates a new instance if none exists.

Parameters:

  • batch (BatchCounter, nil)

    An existing BatchCounter to update or nil to create a new one

  • query (Hash)

    The Elasticsearch query containing the batch information

  • size (Integer)

    The size of the current batch; also serves as a default batch size

Returns:

  • (BatchCounter)

    A new BatchCounter created out of the given parameters.



29
30
31
32
33
34
35
# File 'lib/jay_api/elasticsearch/batch_counter.rb', line 29

def self.create_or_update(batch, query, size)
  if batch
    new(query, size, batch.start_next, batch.start_next + size, batch.batch_size)
  else
    new(query, size)
  end
end