From 4272789781f93cc54804ce6f07f14fc90d5e4a45 Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Fri, 12 Jan 2024 06:47:03 -0800 Subject: [PATCH] Do a better job handling e.g. hash data structures in sidecar data (#2987) --- app/models/spotlight/solr_document_sidecar.rb | 4 +++- spec/models/spotlight/solr_document_sidecar_spec.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/spotlight/solr_document_sidecar.rb b/app/models/spotlight/solr_document_sidecar.rb index 38f0afdf2..85045722a 100644 --- a/app/models/spotlight/solr_document_sidecar.rb +++ b/app/models/spotlight/solr_document_sidecar.rb @@ -101,8 +101,10 @@ def custom_fields def convert_stored_value_to_solr(value) if value.blank? nil - elsif value.is_a? Enumerable + elsif value.is_a? Array value.reject(&:blank?) + elsif value.is_a? Hash + value.values.reject(&:blank?) else value end diff --git a/spec/models/spotlight/solr_document_sidecar_spec.rb b/spec/models/spotlight/solr_document_sidecar_spec.rb index f3b66b0f2..5be5f9df0 100644 --- a/spec/models/spotlight/solr_document_sidecar_spec.rb +++ b/spec/models/spotlight/solr_document_sidecar_spec.rb @@ -44,5 +44,15 @@ its(:to_solr) { is_expected.to include 'a_blank_multivalued_field' => [] } its(:to_solr) { is_expected.to include 'a_multivalued_field_with_some_blanks' => ['a'] } end + + context 'with other data structures' do + before do + subject.data = { + 'a_hash_field' => { 'a' => 'b' } + } + end + + its(:to_solr) { is_expected.to include 'a_hash_field' => ['b'] } + end end end