diff --git a/app/models/concerns/digital_object/index_and_search/index.rb b/app/models/concerns/digital_object/index_and_search/index.rb index 381ec04ae..d956d3ada 100644 --- a/app/models/concerns/digital_object/index_and_search/index.rb +++ b/app/models/concerns/digital_object/index_and_search/index.rb @@ -51,6 +51,7 @@ def to_solr doc[:search_identifier_sim] << pid doc[:search_identifier_sim].push(*identifiers) # Also append all identifiers to the array + doc[:search_identifier_sim] << self.doi.sub(/^doi:/, '') if self.doi.present? # Also append DOI to the array doc[:search_keyword_teim] << pid if flattened_dynamic_field_data.present? diff --git a/spec/models/concerns/digital_object/index_and_search/index_spec.rb b/spec/models/concerns/digital_object/index_and_search/index_spec.rb new file mode 100644 index 000000000..6547a5a7a --- /dev/null +++ b/spec/models/concerns/digital_object/index_and_search/index_spec.rb @@ -0,0 +1,27 @@ +require 'rails_helper' + +describe DigitalObject::IndexAndSearch::Index do + let(:pid) { 'cul:12345' } + let(:identifiers) { ['id1', 'id2'] } + let(:doi) { 'doi:10.7916/sa43-bk43' } + let(:doi_without_prefix) { doi.gsub(/^doi:/, '') } + let(:project) { Project.new(display_label: 'Sample Project') } + let(:digital_object) { + DigitalObject::Item.new.tap do |obj| + obj.identifiers = identifiers + obj.doi = doi + allow(obj).to receive(:pid).and_return(pid) + allow(obj).to receive(:project).and_return(project) + end + } + + let(:solr_doc) { digital_object.to_solr } + + describe '#to_solr' do + context 'search_identifier_sim field' do + it 'sets the expected values' do + expect(solr_doc[:search_identifier_sim]).to eq([pid] + identifiers + [doi_without_prefix]) + end + end + end +end