Class: Harvestdor::Indexer::Solr

Inherits:
Object
  • Object
show all
Defined in:
lib/harvestdor/indexer/solr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(indexer, config = {}) ⇒ Solr

Returns a new instance of Solr.



5
6
7
8
9
10
# File 'lib/harvestdor/indexer/solr.rb', line 5

def initialize(indexer, config = {})
  @indexer = indexer
  @client = RSolr.connect(config)
  @config = Confstruct::Configuration.new config
  @config.max_retries ||= 10
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



3
4
5
# File 'lib/harvestdor/indexer/solr.rb', line 3

def client
  @client
end

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/harvestdor/indexer/solr.rb', line 3

def config
  @config
end

#indexerObject

Returns the value of attribute indexer.



3
4
5
# File 'lib/harvestdor/indexer/solr.rb', line 3

def indexer
  @indexer
end

Instance Method Details

#add(doc, coll_size = '?', index = '?') ⇒ Object

Add the document to solr, retry if an error occurs. See github.com/ooyala/retries for docs on with_retries.

Parameters:

  • doc (Hash)

    a Hash representation of the solr document

  • coll_size (String) (defaults to: '?')

    the size of the collection

  • index (String) (defaults to: '?')

    the index of this document (nth to be indexed)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/harvestdor/indexer/solr.rb', line 25

def add(doc, coll_size = '?', index = '?')
  id = doc[:id]

  handler = proc do |exception, attempt_number, _total_delay|
    logger.debug "#{exception.class} on attempt #{attempt_number} for #{id}"
    # logger.debug exception.backtrace
  end

  with_retries(max_tries: config.max_retries, handler: handler, base_sleep_seconds: 1, max_sleep_seconds: 5) do |attempt|
    logger.debug "Attempt #{attempt} for #{id}"
    client.add(doc)
    logger.info "Successfully indexed #{id} (#{index}/#{coll_size}) on attempt #{attempt}"
  end
end

#commit!Object



16
17
18
# File 'lib/harvestdor/indexer/solr.rb', line 16

def commit!
  client.commit
end

#loggerObject



12
13
14
# File 'lib/harvestdor/indexer/solr.rb', line 12

def logger
  indexer.logger
end