Skip to content

Commit

Permalink
Do a better job handling e.g. hash data structures in sidecar data (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer authored Jan 12, 2024
1 parent dc2d236 commit 4272789
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/spotlight/solr_document_sidecar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/models/spotlight/solr_document_sidecar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4272789

Please sign in to comment.