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
- #sourceId ⇒ Object
- #sourceId=(value) ⇒ Object
- #tags ⇒ Object
- #to_solr(solr_doc = Hash.new, *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
70 71 72 73 74 75 76 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 70 def add_otherId(other_id) (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 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 30 def add_value(name, value, attrs={}) add_child_node(ng_xml.root, :value, name, value, attrs) end |
#objectId ⇒ Object
34 35 36 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 34 def objectId self.find_by_terms(:objectId).text end |
#otherId(type = nil) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 61 def otherId(type = nil) result = self.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 |
#sourceId ⇒ Object
38 39 40 41 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 38 def sourceId node = self.find_by_terms(:sourceId).first node ? [node['source'],node.text].join(':') : nil end |
#sourceId=(value) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 43 def sourceId=(value) node = self.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 (source, val) = value.split(/:/, 2) raise ArgumentError, "Source ID must follow the format namespace:value, not '#{value}'" unless source.present? && val.present? node ||= ng_xml.root.add_child('<sourceId/>').first node['source'] = source node.content = val node end |
#tags ⇒ Object
57 58 59 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 57 def self.ng_xml.search('//tag').collect(&:content) end |
#to_solr(solr_doc = Hash.new, *args) ⇒ Object
78 79 80 81 82 83 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 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 78 def to_solr(solr_doc=Hash.new, *args) 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 self.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 } return solr_doc end |