Skip to content

Commit

Permalink
Index subject fields to combined_subject facet (#836)
Browse files Browse the repository at this point in the history
Co-authored-by: parinita <[email protected]>
  • Loading branch information
sourcefilter and pghorpade authored Aug 11, 2020
1 parent 625058a commit 6363d77
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/indexers/work_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,28 @@ class WorkIndexer < Hyrax::WorkIndexer

def generate_solr_document
super.tap do |solr_doc|
solr_doc['sort_year_isi'] = years.to_a.min
solr_doc['combined_subject_ssim'] = combined_subject
solr_doc['date_dtsim'] = solr_dates
solr_doc['geographic_coordinates_ssim'] = coordinates
solr_doc['human_readable_iiif_text_direction_ssi'] = human_readable_iiif_text_direction
solr_doc['human_readable_iiif_viewing_hint_ssi'] = human_readable_iiif_viewing_hint
solr_doc['human_readable_language_sim'] = human_readable_language
solr_doc['human_readable_language_tesim'] = human_readable_language
solr_doc['human_readable_resource_type_sim'] = human_readable_resource_type
solr_doc['human_readable_resource_type_tesim'] = human_readable_resource_type
solr_doc['human_readable_iiif_text_direction_ssi'] = human_readable_iiif_text_direction
solr_doc['human_readable_iiif_viewing_hint_ssi'] = human_readable_iiif_viewing_hint
solr_doc['human_readable_rights_statement_tesim'] = human_readable_rights_statement
solr_doc['sort_year_isi'] = years.to_a.min
solr_doc['thumbnail_url_ss'] = thumbnail_url
solr_doc['title_alpha_numeric_ssort'] = object.title.first
solr_doc['ursus_id_ssi'] = Californica::IdGenerator.blacklight_id_from_ark(object.ark)
solr_doc['year_isim'] = years
solr_doc['date_dtsim'] = solr_dates
solr_doc['thumbnail_url_ss'] = thumbnail_url
end
end

def combined_subject
object.named_subject.to_a + object.subject.to_a + object.subject_topic.to_a + object.subject_geographic.to_a + object.subject_temporal.to_a
end

def coordinates
return unless object.latitude.first && object.longitude.first
[object.latitude.first, object.longitude.first].join(', ')
Expand Down
30 changes: 30 additions & 0 deletions spec/indexers/work_indexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@
let(:work) { Work.new(attributes) }
let(:indexer) { described_class.new(work) }

describe 'combined_subject' do
let(:attributes) do
{
ark: 'ark:/123/456',
subject: ['Subject 1', 'Subject 2'],
named_subject: ['Named Subject'],
subject_topic: ['Subject Topic'],
subject_geographic: ['Subject Geographic']
}
end

it 'combines the relevant subject fields' do
expect(solr_document['combined_subject_ssim']).to contain_exactly('Subject 1', 'Subject 2', 'Named Subject', 'Subject Topic', 'Subject Geographic')
end

context 'When subject fields are missing' do
let(:attributes) do
{
ark: 'ark:/123/456',
named_subject: ['Named Subject'],
subject_topic: ['Subject Topic']
}
end

it 'combines the fields that are present' do
expect(solr_document['combined_subject_ssim']).to contain_exactly('Named Subject', 'Subject Topic')
end
end
end

describe 'resource type' do
context 'a work with a resource type' do
let(:attributes) do
Expand Down

0 comments on commit 6363d77

Please sign in to comment.