class Solr4R::Batch
Constants
- DEFAULT_SIZE
- STEP
Attributes
client[R]
size[RW]
Public Class Methods
new(client, attributes = {}, params = {}, options = {}, size = DEFAULT_SIZE, &block)
click to toggle source
# File lib/solr4r/batch.rb, line 33 def initialize(client, attributes = {}, params = {}, options = {}, size = DEFAULT_SIZE, &block) @client, @args, @size, @block = client, [attributes, params, options], size, block reset end
Public Instance Methods
add(*docs)
click to toggle source
# File lib/solr4r/batch.rb, line 53 def add(*docs) batch(docs) end
Also aliased as: <<
batch(docs)
click to toggle source
# File lib/solr4r/batch.rb, line 59 def batch(docs) flush unless @batch.concat(docs).size < size end
clear()
click to toggle source
# File lib/solr4r/batch.rb, line 49 def clear @batch.clear end
flush()
click to toggle source
# File lib/solr4r/batch.rb, line 63 def flush process clear @failed end
inspect()
click to toggle source
# File lib/solr4r/batch.rb, line 69 def inspect '#<%s:0x%x @size=%p, @count=%p, @failed=%p>' % [ self.class, object_id, size, @batch.size, @failed.size ] end
reset()
click to toggle source
# File lib/solr4r/batch.rb, line 45 def reset @batch, @failed = [], [] end
Private Instance Methods
process(docs = @batch, size = size())
click to toggle source
# File lib/solr4r/batch.rb, line 77 def process(docs = @batch, size = size()) next_size = size.fdiv(STEP).ceil docs.each_slice(size) { |batch| client.add(batch, *@args, &@block).success? ? nil : size > 1 ? process(batch, next_size) : @failed.concat(batch) } end