Class: BaseIndexer::MainIndexerEngine

Inherits:
Object
  • Object
show all
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

Examples:

Index with target list

indexer = BaseIndexer::MainIndexerEngine.new
indexer.index "ab123cd456", ["searchworks","revs"]

Index from release_tags

indexer = BaseIndexer::MainIndexerEngine.new
indexer.index "ab123cd456"

Delete item from all solr cores

indexer = BaseIndexer::MainIndexerEngine.new
indexer.delete "ab123cd456"

Instance Method Summary collapse

Instance Method Details

#delete(druid) ⇒ Object

It deletes an item defined by druid from all registered solr core

Parameters:

  • druid (String)

    is the druid for an object e.g., ab123cd4567



55
56
57
58
# File 'lib/base_indexer/main_indexer_engine.rb', line 55

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

#get_collection_names(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

Parameters:

  • collection_druids (Array)

    a list of druids ![“ab123cd4567”, “ef123gh4567”]

Returns:

  • (Hash)

    a hash for collection druid and its name {“ab123cd4567”=>“Collection 1”, “ef123gh4567”=>“Collection 2”}



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/base_indexer/main_indexer_engine.rb', line 99

def get_collection_names collection_druids
  collection_names = {}
  
  unless collection_druids.nil? then
    collection_druids.each do |cdruid|
      cname = BaseIndexer::Collection.get_collection_name(cdruid)
      collection_names[cdruid] = cname unless cname.nil? 
    end
  end
  collection_names
end

#get_targets_hash_from_param(targets) ⇒ Hash

It converts targets array to targets hash

Examples:

convert target list

get_targets_hash_from_param( ["searchworks","revs"] )
{"searchworks"=>true, "revs"=>true}

Parameters:

  • targets (Array)

    a list of specfic targets

Returns:

  • (Hash)

    a hash of targets with true value



74
75
76
77
78
79
80
81
82
# File 'lib/base_indexer/main_indexer_engine.rb', line 74

def get_targets_hash_from_param(targets)
  targets_hash = {}
  unless targets.nil? then
    targets.each do |target|
      targets_hash[target] = true
    end
  end
  return targets_hash
end

#index(druid, targets = nil) ⇒ Object

It is the main indexing function

Parameters:

  • druid (String)

    is the druid for an object e.g., ab123cd4567

  • targets (Array) (defaults to: nil)

    is an array with the targets list to index towards, if it is nil, the method will read the target list from release_tags

Raises:

  • it will raise erros if there is any problems happen in any level



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/base_indexer/main_indexer_engine.rb', line 29

def index druid, targets=nil
  # Read input mods and purl
  purl_model =  read_purl(druid)
  mods_model =  read_mods(druid)
  collection_names = get_collection_names(purl_model.collection_druids)
  
  # Map the input to solr_doc
  solr_doc =  BaseIndexer.mapper_class_name.constantize.new(druid, mods_model, purl_model, collection_names).convert_to_solr_doc
  
  # Get target list
  targets_hash={}
  if targets.nil? or targets.length == 0
    targets_hash = purl_model.release_tags_hash
  else
    targets_hash = get_targets_hash_from_param(targets)
  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



64
65
66
# File 'lib/base_indexer/main_indexer_engine.rb', line 64

def read_mods druid
  return DiscoveryIndexer::InputXml::Modsxml.new(druid).load()
end

#read_purl(druid) ⇒ Object



60
61
62
# File 'lib/base_indexer/main_indexer_engine.rb', line 60

def read_purl druid
  return DiscoveryIndexer::InputXml::Purlxml.new(druid).load()
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

Parameters:

  • targets_hash (Hash)

    a hash of targets with true value

  • purl_model (DiscoveryIndexer::Reader::PurlxmlModel)

    represents the purlxml model

Returns:

  • (Hash)

    a hash of targets



89
90
91
# File 'lib/base_indexer/main_indexer_engine.rb', line 89

def update_targets_before_write(targets_hash, purl_model)
  return targets_hash
end