app/models/spotlight/solr_document_sidecar.rb in blacklight-spotlight-0.4.1 vs app/models/spotlight/solr_document_sidecar.rb in blacklight-spotlight-0.5.0
- old
+ new
@@ -1,12 +1,14 @@
module Spotlight
+ ##
+ # Exhibit-specific metadata for indexed documents
class SolrDocumentSidecar < ActiveRecord::Base
belongs_to :exhibit
belongs_to :document, polymorphic: true
serialize :data, Hash
- delegate :has_key?, to: :data
+ delegate :has_key?, :key?, to: :data
def to_solr
{ document.class.unique_key.to_sym => document.id, visibility_field => public? }.merge(data_to_solr)
end
@@ -40,28 +42,28 @@
def blacklight_config
exhibit.blacklight_config
end
def data_to_solr
- data.except("configured_fields").merge(configured_fields_data_to_solr)
+ data.except('configured_fields').merge(configured_fields_data_to_solr)
end
def configured_fields_data_to_solr
- solr_hash = {}
- if data["configured_fields"]
- configured_fields = Spotlight::Resources::Upload.fields(exhibit)
+ configured_fields = data.fetch('configured_fields', {})
- configured_fields.each do |field|
- solr_fields = Array(field.solr_field || field.field_name)
- if data["configured_fields"][field.field_name.to_s].present?
- solr_fields.each do |solr_field|
- solr_hash[solr_field] = data["configured_fields"][field.field_name.to_s]
- end
- end
+ upload_fields.each_with_object({}) do |field, solr_hash|
+ field_name = field.field_name.to_s
+ next unless configured_fields && configured_fields[field_name].present?
+
+ solr_fields = Array(field.solr_field || field.field_name)
+
+ solr_fields.each do |solr_field|
+ solr_hash[solr_field] = configured_fields[field_name]
end
end
-
- solr_hash.select { |k,v| v.present? }
end
+ def upload_fields
+ Spotlight::Resources::Upload.fields(exhibit)
+ end
end
end