Class: Dor::IdentityMetadataDS
- Inherits:
-
ActiveFedora::OmDatastream
- Object
- ActiveFedora::OmDatastream
- Dor::IdentityMetadataDS
- Includes:
- SolrDocHelper
- Defined in:
- lib/dor/datastreams/identity_metadata_ds.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_otherId(other_id) ⇒ Object
- #add_value(name, value, attrs = {}) ⇒ Object
- #objectId ⇒ Object
- #otherId(type = nil) ⇒ Object
-
#prefix ⇒ Object
maintain AF < 8 indexing behavior.
- #sourceId ⇒ Object
-
#sourceId=(value) ⇒ String, Nil
The same value, as per Ruby convention for assignment operators.
- #tags ⇒ Object
- #to_solr(solr_doc = {}, *args) ⇒ Object
Methods included from SolrDocHelper
Class Method Details
.xml_template ⇒ Object
26 27 28 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 26 def self.xml_template Nokogiri::XML('<identityMetadata/>') end |
Instance Method Details
#add_otherId(other_id) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 75 def add_otherId(other_id) ng_xml_will_change! (name, val) = other_id.split(/:/, 2) node = ng_xml.root.add_child('<otherId/>').first node['name'] = name node.content = val node end |
#add_value(name, value, attrs = {}) ⇒ Object
30 31 32 33 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 30 def add_value(name, value, attrs = {}) ng_xml_will_change! add_child_node(ng_xml.root, :value, name, value, attrs) end |
#objectId ⇒ Object
35 36 37 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 35 def objectId find_by_terms(:objectId).text end |
#otherId(type = nil) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 66 def otherId(type = nil) result = find_by_terms(:otherId).to_a if type.nil? result.collect { |n| [n['name'], n.text].join(':') } else result.select { |n| n['name'] == type }.collect { |n| n.text } end end |
#prefix ⇒ Object
maintain AF < 8 indexing behavior
135 136 137 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 135 def prefix '' end |
#sourceId ⇒ Object
39 40 41 42 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 39 def sourceId node = find_by_terms(:sourceId).first node ? [node['source'], node.text].join(':') : nil end |
#sourceId=(value) ⇒ String, Nil
Note:
The actual values assigned will have leading/trailing whitespace stripped.
Returns The same value, as per Ruby convention for assignment operators.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 47 def sourceId=(value) ng_xml_will_change! node = find_by_terms(:sourceId).first unless value.present? # so setting it to '' is the same as removal: worth documenting maybe? node.remove unless node.nil? return nil end parts = value.split(':', 2).map(&:strip) raise ArgumentError, "Source ID must follow the format 'namespace:value', not '#{value}'" unless parts.length == 2 && parts[0].present? && parts[1].present? node ||= ng_xml.root.add_child('<sourceId/>').first node['source'] = parts[0] node.content = parts[1] end |
#tags ⇒ Object
62 63 64 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 62 def ng_xml.search('//tag').collect(&:content) end |
#to_solr(solr_doc = {}, *args) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 84 def to_solr(solr_doc = {}, *args) solr_doc = super(solr_doc, *args) if digital_object.respond_to?(:profile) digital_object.profile.each_pair do |property, value| add_solr_value(solr_doc, property.underscore, value, (property =~ /Date/ ? :date : :symbol), [:stored_searchable]) end end if sourceId.present? (name, id) = sourceId.split(/:/, 2) add_solr_value(solr_doc, 'dor_id', id, :symbol, [:stored_searchable]) add_solr_value(solr_doc, 'identifier', sourceId, :symbol, [:stored_searchable]) add_solr_value(solr_doc, 'source_id', sourceId, :symbol, []) end otherId.compact.each { |qid| # this section will solrize barcode and catkey, which live in otherId (name, id) = qid.split(/:/, 2) add_solr_value(solr_doc, 'dor_id', id, :symbol, [:stored_searchable]) add_solr_value(solr_doc, 'identifier', qid, :symbol, [:stored_searchable]) add_solr_value(solr_doc, "#{name}_id", id, :symbol, []) } # do some stuff to make tags in general and project tags specifically more easily searchable and facetable find_by_terms(:tag).each { |tag| (prefix, rest) = tag.text.split(/:/, 2) prefix = prefix.downcase.strip.gsub(/\s/, '_') unless rest.nil? # this part will index a value in a field specific to the tag, e.g. registered_by_tag_*, # book_tag_*, project_tag_*, remediated_by_tag_*, etc. project_tag_* and registered_by_tag_* # definitley get used, but most don't. we can limit the prefixes that get solrized if things # get out of hand. add_solr_value(solr_doc, "#{prefix}_tag", rest.strip, :symbol, []) end # solrize each possible prefix for the tag, inclusive of the full tag. # e.g., for a tag such as "A : B : C", this will solrize to an _ssim field # that contains ["A", "A : B", "A : B : C"]. tag_parts = tag.text.split(/:/) progressive_tag_prefix = '' tag_parts.each_with_index do |part, index| progressive_tag_prefix += ' : ' if index > 0 progressive_tag_prefix += part.strip add_solr_value(solr_doc, 'exploded_tag', progressive_tag_prefix, :symbol, []) end } solr_doc end |