Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add patch for SolrDocument#location_label #815

Merged
merged 1 commit into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions app/models/concerns/spot/solr_document_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,20 @@ module SolrDocumentAttributes
# dates
attribute :date_modified, ::Blacklight::Types::Date, 'date_modified_dtsi'

# Helper while we reindex the collection to use the new `subject_label_tesim` property
# but falling back to the old `subject_label_ssim` if those values aren't present.
# If both fields are defined (which shouldn't happen), the newer "_tesim" field will be
# used if content exists.
# Patching while we reindex the collection to use the new `location_label_tesim` and
# `subject_label_tesim` properties but falling back to their old `*_label_ssim` counterparts
# if the others aren't present. This should help the old values appear during a collection
# reindex. If both fields are present (which shouldn't happen), the newer "_tesim" field
# will be used.
#
# Placed in the `included` block to overwrite the `attribute :subject_label` definition
# above (defining this outside of the `included` block will cause the `attribute` definition to override)
# Placed in the `included` block to overwrite the `attribute` definitions, which are defined
# after methods in the mixin.
#
# @todo remove this after reindexing, 2022-01-10
def location_label
Array.wrap(self['location_label_tesim'] || self['location_label_ssim'])
end

def subject_label
Array.wrap(self['subject_label_tesim'] || self['subject_label_ssim'])
end
Expand Down
20 changes: 20 additions & 0 deletions spec/models/solr_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@
end
end

describe '#location_label patch' do
subject { document.location_label }

context 'when location_label stored as string (_ssim)' do
let(:metadata) do
{ 'location_label_ssim' => ['Location Label'] }
end

it { is_expected.to eq ['Location Label'] }
end

context 'when location_label stored as text (_tesim)' do
let(:metadata) do
{ 'location_label_tesim' => ['Location Label'] }
end

it { is_expected.to eq ['Location Label'] }
end
end

describe '#subject_label patch' do
subject { document.subject_label }

Expand Down