Class: GDor::Indexer::SolrDocBuilder

Inherits:
Object
  • Object
show all
Includes:
ModsFields, PublicXmlFields
Defined in:
lib/gdor/indexer/solr_doc_builder.rb

Overview

Class to build the Hash representing a Solr document for a particular druid

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PublicXmlFields

#collection?, #collections, #display_type, #file_ids

Methods included from ModsFields

#doc_hash_from_mods

Constructor Details

#initialize(resource, logger) ⇒ SolrDocBuilder

Returns a new instance of SolrDocBuilder.

Parameters:

  • resource (Harvestdor::Indexer::Resource)

    used to get MODS and public_xml

  • logger (Logger)

    for indexing messages



20
21
22
23
# File 'lib/gdor/indexer/solr_doc_builder.rb', line 20

def initialize(resource, logger)
  @resource = resource
  @logger = logger
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



16
17
18
# File 'lib/gdor/indexer/solr_doc_builder.rb', line 16

def logger
  @logger
end

#resourceObject (readonly)

The druid of the item



15
16
17
# File 'lib/gdor/indexer/solr_doc_builder.rb', line 15

def resource
  @resource
end

Instance Method Details

#catkeyString

first we look for

/otherId[@name='catkey']

if not found, we look for

identityMetadata/otherId[@name='barcode']
 if found, we look for catkey in MODS
   mods/recordInfo/recordIdentifier[@source="SIRSI"]
   and if found, remove the leading a

otherwise, nil

Returns:

  • (String)

    value with SIRSI/Symphony numeric catkey in it, or nil if none exists



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gdor/indexer/solr_doc_builder.rb', line 49

def catkey
  @catkey ||= begin
    catkey = nil
    node = public_xml.xpath("/publicObject/identityMetadata/otherId[@name='catkey']") if public_xml
    catkey = node.first.content if node && node.first
    unless catkey
      # if there's a barcode in the identity metadata then look for a ckey in the MODS
      node = public_xml.xpath("/publicObject/identityMetadata/otherId[@name='barcode']")
      if node.first
        rec_id = smods_rec.record_info.recordIdentifier
        if rec_id && !rec_id.empty? && rec_id.first.source == 'SIRSI'
          catkey = rec_id.first.text.delete('a') # need to ensure catkey is numeric only
        else
          logger.error("#{druid} has barcode #{node.first.content} in identityMetadata but no SIRSI catkey in mods")
        end
      end
    end
    catkey
  end
end

#doc_hashHash

Create a Hash representing the Solr doc to be written to Solr, based on MODS and public_xml

Returns:

  • (Hash)

    Hash representing the Solr document



31
32
33
34
35
36
37
38
# File 'lib/gdor/indexer/solr_doc_builder.rb', line 31

def doc_hash
  @doc_hash ||= begin
    doc_hash = GDor::Indexer::SolrDocHash.new id: resource.bare_druid, modsxml: smods_rec.to_xml
    hash_from_mods = doc_hash_from_mods # defined in gdor_mods_fields
    doc_hash.merge!(hash_from_mods) if hash_from_mods
    doc_hash
  end
end

#druidObject



25
26
27
# File 'lib/gdor/indexer/solr_doc_builder.rb', line 25

def druid
  resource.druid
end

#public_xmlNokogiri::XML::Document

the public_xml for the druid as a Nokogiri::XML::Document object

Returns:

  • (Nokogiri::XML::Document)

    containing the public xml for the druid



82
83
84
# File 'lib/gdor/indexer/solr_doc_builder.rb', line 82

def public_xml
  resource.public_xml
end

#smods_recStanford::Mods::Record

return the MODS for the druid as a Stanford::Mods::Record object

Returns:

  • (Stanford::Mods::Record)

    created from the MODS xml for the druid



72
73
74
75
76
77
78
# File 'lib/gdor/indexer/solr_doc_builder.rb', line 72

def smods_rec
  @smods_rec ||= begin
    mods_rec = resource.smods_rec
    mods_rec.druid = druid # why?
    mods_rec
  end
end