Class: Harvestdor::Indexer::Solr
- Inherits:
-
Object
- Object
- Harvestdor::Indexer::Solr
- Defined in:
- lib/harvestdor/indexer/solr.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#config ⇒ Object
Returns the value of attribute config.
-
#indexer ⇒ Object
Returns the value of attribute indexer.
Instance Method Summary collapse
-
#add(doc, coll_size = '?', index = '?') ⇒ Object
Add the document to solr, retry if an error occurs.
- #commit! ⇒ Object
-
#initialize(indexer, config = {}) ⇒ Solr
constructor
A new instance of Solr.
- #logger ⇒ Object
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
#client ⇒ Object
Returns the value of attribute client.
3 4 5 |
# File 'lib/harvestdor/indexer/solr.rb', line 3 def client @client end |
#config ⇒ Object
Returns the value of attribute config.
3 4 5 |
# File 'lib/harvestdor/indexer/solr.rb', line 3 def config @config end |
#indexer ⇒ Object
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.
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 |
#logger ⇒ Object
12 13 14 |
# File 'lib/harvestdor/indexer/solr.rb', line 12 def logger indexer.logger end |