Class: GDor::Indexer::SolrDocHash
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- GDor::Indexer::SolrDocHash
- Defined in:
- lib/gdor/indexer/solr_doc_hash.rb
Overview
Hash-like SolrDoc Object class
Instance Method Summary collapse
-
#combine(new_hash) ⇒ GDor::Indexer::SolrDocHash
merge in field values from the new hash, with the following guarantees: values for keys in new_hash will be a non-empty String or flat Array keys will be removed from hash if all values are nil or empty.
-
#compact_blank_fields! ⇒ GDor::Indexer::SolrDocHash
Self.
- #druid ⇒ String
-
#field_present?(field, exp_val = nil) ⇒ Boolean
when exp_val is nil, looks for non-empty existence of field when exp_val is a String, looks for matching value as a String or as a member of an Array when exp_val is a Regexp, looks for String value that matches, or Array with a String member that matches.
-
#initialize(hash = {}) ⇒ SolrDocHash
constructor
A new instance of SolrDocHash.
-
#validate_collection(config) ⇒ Object
validate fields that should be in hash for any collection object in SearchWorks Solr.
-
#validate_gdor_fields(config) ⇒ Object
validate fields that should be in hash for every gryphonDOR object in SearchWorks Solr.
-
#validate_item(config) ⇒ Array<String>
validate fields that should be in hash for any item object in SearchWorks Solr.
-
#validate_mods(_config) ⇒ Object
validate fields that should be in doc hash for every unmerged gryphonDOR object in SearchWorks Solr.
Constructor Details
#initialize(hash = {}) ⇒ SolrDocHash
Returns a new instance of SolrDocHash.
6 7 8 |
# File 'lib/gdor/indexer/solr_doc_hash.rb', line 6 def initialize(hash = {}) super(hash) end |
Instance Method Details
#combine(new_hash) ⇒ GDor::Indexer::SolrDocHash
merge in field values from the new hash, with the following guarantees:
values for keys in new_hash will be a non-empty String or flat Array
keys will be removed from hash if all values are nil or empty
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/gdor/indexer/solr_doc_hash.rb', line 34 def combine(new_hash) new_hash.select { |_key, value| Array(value).any? { |v| !v.blank? } }.each do |key, new_val| if field_present? key orig_val = self[key] case orig_val when Array self[key] += Array(new_val) else self[key] = Array(orig_val) + Array(new_val) end self[key] = self[key].reject(&:blank?).uniq else self[key] = new_val end end compact_blank_fields! self end |
#compact_blank_fields! ⇒ GDor::Indexer::SolrDocHash
Returns self.
56 57 58 59 60 61 |
# File 'lib/gdor/indexer/solr_doc_hash.rb', line 56 def compact_blank_fields! keys.reject { |key| field_present? key }.each do |key| delete key end self end |
#druid ⇒ String
64 65 66 |
# File 'lib/gdor/indexer/solr_doc_hash.rb', line 64 def druid self[:druid] end |
#field_present?(field, exp_val = nil) ⇒ Boolean
when exp_val is nil, looks for non-empty existence of field when exp_val is a String, looks for matching value as a String or as a member of an Array when exp_val is a Regexp, looks for String value that matches, or Array with a String member that matches
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gdor/indexer/solr_doc_hash.rb', line 15 def field_present?(field, exp_val = nil) return false unless include?(field) return false unless Array(self[field]).any?(&:present?) case exp_val when nil true when Regexp Array(self[field]).any? { |s| exp_val.match(s) } else Array(self[field]).include? exp_val end end |
#validate_collection(config) ⇒ Object
validate fields that should be in hash for any collection object in SearchWorks Solr
84 85 86 87 88 89 |
# File 'lib/gdor/indexer/solr_doc_hash.rb', line 84 def validate_collection(config) result = validate_gdor_fields(config) result << "#{druid} missing collection_type 'Digital Collection'\n" unless field_present?(:collection_type, 'Digital Collection') result << "#{druid} missing format_main_ssim 'Archive/Manuscript'\n" unless field_present?(:format_main_ssim, 'Archive/Manuscript') result end |
#validate_gdor_fields(config) ⇒ Object
validate fields that should be in hash for every gryphonDOR object in SearchWorks Solr
93 94 95 96 97 98 99 100 101 |
# File 'lib/gdor/indexer/solr_doc_hash.rb', line 93 def validate_gdor_fields(config) result = [] result << "#{druid} missing druid field\n" unless field_present?(:druid, druid) result << "#{druid} missing url_fulltext for purl\n" unless field_present?(:url_fulltext, "#{config.harvestdor.purl}/#{druid}") result << "#{druid} missing access_facet 'Online'\n" unless field_present?(:access_facet, 'Online') result << "#{druid} missing or bad display_type, possibly caused by unrecognized @type attribute on <contentMetadata>\n" unless field_present?(:display_type, /(file)|(image)|(media)|(book)/) result << "#{druid} missing building_facet 'Stanford Digital Repository'\n" unless field_present?(:building_facet, 'Stanford Digital Repository') result end |
#validate_item(config) ⇒ Array<String>
validate fields that should be in hash for any item object in SearchWorks Solr
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/gdor/indexer/solr_doc_hash.rb', line 71 def validate_item(config) result = validate_gdor_fields(config) result << "#{druid} missing collection\n" unless field_present?(:collection) Array(self[:collection]).each do |collection_druid| result << "#{druid} missing collection_with_title (or collection #{collection_druid} is missing title)\n" unless field_present?(:collection_with_title, Regexp.new("#{collection_druid}-\\|-.+")) end result << "#{druid} missing file_id(s)\n" unless field_present?(:file_id) result end |
#validate_mods(_config) ⇒ Object
validate fields that should be in doc hash for every unmerged gryphonDOR object in SearchWorks Solr
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/gdor/indexer/solr_doc_hash.rb', line 105 def validate_mods(_config) result = [] result << "#{druid} missing modsxml\n" unless field_present?(:modsxml) result << "#{druid} missing resource type\n" unless field_present?(:format_main_ssim) result << "#{druid} missing format\n" unless field_present?(:format) # for backwards compatibility result << "#{druid} missing title\n" unless field_present?(:title_display) result << "#{druid} missing pub year for date slider\n" unless field_present?(:pub_year_tisim) result << "#{druid} missing author\n" unless field_present?(:author_person_display) result << "#{druid} missing language\n" unless field_present?(:language) result end |