Class: GDor::Indexer::SolrDocBuilder
- Inherits:
-
Object
- Object
- GDor::Indexer::SolrDocBuilder
- 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
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#resource ⇒ Object
readonly
The druid of the item.
Instance Method Summary collapse
-
#catkey ⇒ String
first we look for identityMetadata/otherId if not found, we look for identityMetadata/otherId if found, we look for catkey in MODS mods/recordInfo/recordIdentifier and if found, remove the leading a otherwise, nil.
-
#doc_hash ⇒ Hash
Create a Hash representing the Solr doc to be written to Solr, based on MODS and public_xml.
- #druid ⇒ Object
-
#initialize(resource, logger) ⇒ SolrDocBuilder
constructor
A new instance of SolrDocBuilder.
-
#public_xml ⇒ Nokogiri::XML::Document
the public_xml for the druid as a Nokogiri::XML::Document object.
-
#smods_rec ⇒ Stanford::Mods::Record
return the MODS for the druid as a Stanford::Mods::Record object.
Methods included from PublicXmlFields
#collection?, #collections, #display_type, #file_ids
Methods included from ModsFields
Constructor Details
#initialize(resource, logger) ⇒ SolrDocBuilder
Returns a new instance of SolrDocBuilder.
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
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
16 17 18 |
# File 'lib/gdor/indexer/solr_doc_builder.rb', line 16 def logger @logger end |
#resource ⇒ Object (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
#catkey ⇒ String
first we look for
identityMetadata/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
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_hash ⇒ Hash
Create a Hash representing the Solr doc to be written to Solr, based on MODS and public_xml
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., 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 |
#druid ⇒ Object
25 26 27 |
# File 'lib/gdor/indexer/solr_doc_builder.rb', line 25 def druid resource.druid end |
#public_xml ⇒ Nokogiri::XML::Document
the public_xml for the druid as a Nokogiri::XML::Document object
82 83 84 |
# File 'lib/gdor/indexer/solr_doc_builder.rb', line 82 def public_xml resource.public_xml end |
#smods_rec ⇒ Stanford::Mods::Record
return the MODS for the druid as a Stanford::Mods::Record object
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 |