Class: BaseIndexer::MainIndexerEngine
- Inherits:
-
Object
- Object
- BaseIndexer::MainIndexerEngine
- Includes:
- DiscoveryIndexer
- Defined in:
- lib/base_indexer/main_indexer_engine.rb
Overview
It is responsible for performing the basic indexing steps, it includes reading the input from PURL server, getting collection names, mapping it to solr doc hash, and write it to SOLR core . It can also delete the object from all the registered
Instance Method Summary collapse
-
#collection_data(collection_druids) ⇒ Hash
It converts collection_druids list to a hash with names.
-
#delete(druid) ⇒ Object
It deletes an item defined by druid from all registered solr core.
-
#index(druid, targets = nil) ⇒ Object
It is the main indexing function.
- #read_mods(druid) ⇒ Object
- #read_purl(druid) ⇒ Object
-
#targets_hash_from_param(targets) ⇒ Hash
It converts targets array to targets hash.
-
#update_targets_before_write(targets_hash, _purl_model) ⇒ Hash
It allows the consumer to modify the targets list before doing the final writing to the solr core.
Instance Method Details
#collection_data(collection_druids) ⇒ Hash
It converts collection_druids list to a hash with names. If the druid doesn’t have a collection name, it will be excluded from the hash
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/base_indexer/main_indexer_engine.rb', line 98 def collection_data(collection_druids) collection_data = {} unless collection_druids.nil? collection_druids.each do |cdruid| cdata = BaseIndexer::Collection.new(cdruid).collection_info collection_data[cdruid] = cdata if cdata.present? end end collection_data end |
#delete(druid) ⇒ Object
It deletes an item defined by druid from all registered solr core
54 55 56 57 |
# File 'lib/base_indexer/main_indexer_engine.rb', line 54 def delete(druid) solr_targets_configs = BaseIndexer.solr_configuration_class_name.constantize.instance.get_configuration_hash BaseIndexer.solr_writer_class_name.constantize.new.solr_delete_from_all(druid, solr_targets_configs) end |
#index(druid, targets = nil) ⇒ Object
It is the main indexing function
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/base_indexer/main_indexer_engine.rb', line 28 def index(druid, targets = nil) # Read input mods and purl purl_model = read_purl(druid) mods_model = read_mods(druid) collection_data = collection_data(purl_model.collection_druids) # Map the input to solr_doc solr_doc = BaseIndexer.mapper_class_name.constantize.new(druid, mods_model, purl_model, collection_data).convert_to_solr_doc # Get target list targets_hash = {} if targets.present? targets_hash = targets_hash_from_param(targets) else targets_hash = purl_model. end targets_hash = update_targets_before_write(targets_hash, purl_model) # Get SOLR configuration and write solr_targets_configs = BaseIndexer.solr_configuration_class_name.constantize.instance.get_configuration_hash BaseIndexer.solr_writer_class_name.constantize.new.process(druid, solr_doc, targets_hash, solr_targets_configs) end |
#read_mods(druid) ⇒ Object
63 64 65 |
# File 'lib/base_indexer/main_indexer_engine.rb', line 63 def read_mods(druid) DiscoveryIndexer::InputXml::Modsxml.new(druid).load end |
#read_purl(druid) ⇒ Object
59 60 61 |
# File 'lib/base_indexer/main_indexer_engine.rb', line 59 def read_purl(druid) DiscoveryIndexer::InputXml::Purlxml.new(druid).load end |
#targets_hash_from_param(targets) ⇒ Hash
It converts targets array to targets hash
73 74 75 76 77 78 79 80 81 |
# File 'lib/base_indexer/main_indexer_engine.rb', line 73 def targets_hash_from_param(targets) targets_hash = {} unless targets.nil? targets.each do |target| targets_hash[target] = true end end targets_hash end |
#update_targets_before_write(targets_hash, _purl_model) ⇒ Hash
It allows the consumer to modify the targets list before doing the final writing
to the solr core. Default behavior returns the targets_hash as it is
88 89 90 |
# File 'lib/base_indexer/main_indexer_engine.rb', line 88 def update_targets_before_write(targets_hash, _purl_model) targets_hash end |