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

Parse managed purl 856 fields using their delimited keys #964

Merged
merged 1 commit into from
Jul 10, 2023
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
12 changes: 10 additions & 2 deletions lib/traject/config/sirsi_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2574,18 +2574,26 @@ def library_has(field)

to_field 'collection_struct' do |record, accumulator|
Traject::MarcExtractor.new('856x').collect_matching_lines(record) do |field, spec, extractor|
source, item_type, type, druid, id, title = extractor.collect_subfields(field, spec)
source, item_type, *other_data = extractor.collect_subfields(field, spec)
next unless source == 'SDR-PURL' && item_type == 'item'

data = other_data.to_h { |v| v.split(':', 2) }

next unless data['collection']

druid, id, title = data['collection'].split(':')

accumulator << {
source:,
item_type:,
type:,
type: 'collection',
druid:,
id:,
title:
}
end

accumulator.uniq!
end

to_field 'marc_collection_title_ssim', extract_marc('795ap', alternate_script: false)
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/traject/config/managed_purl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@
expect(select_by_id('ManagedAnd2UnmanagedPurlCollection')[field]).to eq nil
expect(select_by_id('NoManagedPurlItem')[field]).to eq nil
end

context 'collection_struct' do
let(:field) { 'collection_struct' }

it 'maps the right data' do
expect(select_by_id('managedPurlItem1Collection')[field].map do |x|
JSON.parse(x)
end).to match_array [{ 'druid' => 'yg867hg1375', 'id' => '9615156', 'item_type' => 'item', 'source' => 'SDR-PURL', 'title' => 'Francis E. Stafford photographs, 1909-1933', 'type' => 'collection' }]
end
end
end

describe 'collection_type' do
Expand Down