Class: Spotlight::Etl::SolrLoader

Inherits:
Object
  • Object
show all
Defined in:
app/services/spotlight/etl/solr_loader.rb

Overview

Solr data loader with a built-in buffer to combine document updates into batches

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(batch_size: Spotlight::Engine.config.solr_batch_size, solr_connection: nil) ⇒ SolrLoader

Returns a new instance of SolrLoader.



11
12
13
14
15
# File 'app/services/spotlight/etl/solr_loader.rb', line 11

def initialize(batch_size: Spotlight::Engine.config.solr_batch_size, solr_connection: nil)
  @queue = Queue.new
  @batch_size = batch_size
  @blacklight_solr = solr_connection
end

Instance Attribute Details

#batch_sizeObject (readonly)

Returns the value of attribute batch_size.



7
8
9
# File 'app/services/spotlight/etl/solr_loader.rb', line 7

def batch_size
  @batch_size
end

#queueObject (readonly)

Returns the value of attribute queue.



7
8
9
# File 'app/services/spotlight/etl/solr_loader.rb', line 7

def queue
  @queue
end

Instance Method Details

#call(data, pipeline = nil) ⇒ Object



17
18
19
20
21
# File 'app/services/spotlight/etl/solr_loader.rb', line 17

def call(data, pipeline = nil)
  @queue << data

  write_to_index(pipeline) if @queue.size >= @batch_size
end

#finalize(pipeline = nil) ⇒ Object



23
24
25
26
27
# File 'app/services/spotlight/etl/solr_loader.rb', line 23

def finalize(pipeline = nil)
  write_to_index(pipeline)

  commit! if pipeline.nil? || pipeline.context.additional_parameters[:commit]
end