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
34 def initialize(client, attributes = {},
35     params = {}, options = {}, size = DEFAULT_SIZE, &block)
36   @client, @args, @size, @block =
37     client, [attributes, params, options], size, block
38 
39   reset
40 end

Public Instance Methods

<<(*docs)
Alias for: add
add(*docs) click to toggle source
   # File lib/solr4r/batch.rb
54 def add(*docs)
55   batch(docs)
56 end
Also aliased as: <<
batch(docs) click to toggle source
   # File lib/solr4r/batch.rb
60 def batch(docs)
61   flush unless @batch.concat(docs).size < size
62 end
clear() click to toggle source
   # File lib/solr4r/batch.rb
50 def clear
51   @batch.clear
52 end
flush() click to toggle source
   # File lib/solr4r/batch.rb
64 def flush
65   process
66   clear
67   @failed
68 end
inspect() click to toggle source
   # File lib/solr4r/batch.rb
70 def inspect
71   '#<%s:0x%x @size=%p, @count=%p, @failed=%p>' % [
72     self.class, object_id, size, @batch.size, @failed.size
73   ]
74 end
reset() click to toggle source
   # File lib/solr4r/batch.rb
46 def reset
47   @batch, @failed = [], []
48 end

Private Instance Methods

process(docs = @batch, size = size()) click to toggle source
   # File lib/solr4r/batch.rb
78 def process(docs = @batch, size = size())
79   next_size = size.fdiv(STEP).ceil
80 
81   docs.each_slice(size) { |batch|
82     client.add(batch, *@args, &@block).success? ? nil :
83       size > 1 ? process(batch, next_size) : @failed.concat(batch)
84   }
85 end