Skip to content

Commit

Permalink
Merge pull request #1853 from mlibrary/contributor_promotion
Browse files Browse the repository at this point in the history
if creator is blank 'promote' 1st contributor
  • Loading branch information
sethaj authored Jun 6, 2018
2 parents 7298192 + c091584 commit 9cfedf1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/indexers/monograph_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ def generate_solr_document
solr_doc[Solrizer.solr_name('title', :sortable)] = object&.title&.first&.downcase&.gsub(/[^\w\s\d-]/, '')

roleless_creators = multiline_names_minus_role('creator')
roleless_contributors = multiline_names_minus_role('contributor')

# fix for imported Monographs that only have contributors for whatever reason, i.e. the metadata was created...
# outside Fulcrum and only had supposed "non-author roles" which were put in as contributors so we'll promote...
# the first contributor to a creator for use in citations
roleless_creators = [roleless_contributors&.shift] if roleless_creators.blank?

solr_doc[Solrizer.solr_name('creator', :stored_searchable)] = roleless_creators
solr_doc[Solrizer.solr_name('creator_full_name', :stored_searchable)] = roleless_creators&.first
solr_doc[Solrizer.solr_name('creator_full_name', :facetable)] = roleless_creators&.first
solr_doc[Solrizer.solr_name('contributor', :stored_searchable)] = multiline_names_minus_role('contributor')
solr_doc[Solrizer.solr_name('contributor', :stored_searchable)] = roleless_contributors

# grab previous file set order here from Solr (before they are reindexed)
existing_fileset_order = existing_filesets
Expand Down
16 changes: 16 additions & 0 deletions spec/indexers/monograph_indexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@
end
end

describe 'empty creator field' do
subject { indexer.generate_solr_document }

let(:indexer) { described_class.new(monograph) }
let(:monograph) { build(:monograph,
contributor: ["Moose, Bullwinkle\nSquirrel, Rocky"])}
before do
monograph.save!
end

it 'promotes the first contributor to creator' do
expect(subject['creator_tesim']).to eq ['Moose, Bullwinkle']
expect(subject['contributor_tesim']).to eq ['Squirrel, Rocky']
end
end

describe 'representative_manifest_id' do
subject { indexer.generate_solr_document[Solrizer.solr_name('representative_manifest_id', :symbol)] }

Expand Down

0 comments on commit 9cfedf1

Please sign in to comment.