From 9a2da3d336bb7c8aa28b5e4089b66b421ffa4878 Mon Sep 17 00:00:00 2001 From: Ryan Laddusaw Date: Thu, 7 Nov 2024 12:59:56 -0500 Subject: [PATCH 1/4] Index lc_facet field --- marc_to_solr/lib/traject_config.rb | 11 +++++++++++ spec/marc_to_solr/lib/config_spec.rb | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/marc_to_solr/lib/traject_config.rb b/marc_to_solr/lib/traject_config.rb index fb9dffc0..0023ad45 100644 --- a/marc_to_solr/lib/traject_config.rb +++ b/marc_to_solr/lib/traject_config.rb @@ -972,6 +972,17 @@ end end +to_field 'lc_facet' do |record, accumulator| + if record['050'] + if record['050']['a'] + first_letter = record['050']['a'].lstrip.slice(0, 1) + letters = /([[:alpha:]])*/.match(record['050']['a'])[0] + accumulator << Traject::TranslationMap.new("callnumber_map")[first_letter] + accumulator << "#{Traject::TranslationMap.new("callnumber_map")[first_letter]}:#{Traject::TranslationMap.new("callnumber_map")[letters]}" + end + end +end + to_field 'sudoc_facet' do |record, accumulator| MarcExtractor.cached('086|0 |a').collect_matching_lines(record) do |field, spec, extractor| letters = /([[:alpha:]])*/.match(extractor.collect_subfields(field, spec).first)[0] if /([[:alpha:]])*/.match?(extractor.collect_subfields(field, spec).first) diff --git a/spec/marc_to_solr/lib/config_spec.rb b/spec/marc_to_solr/lib/config_spec.rb index d818d5a3..890a71c2 100644 --- a/spec/marc_to_solr/lib/config_spec.rb +++ b/spec/marc_to_solr/lib/config_spec.rb @@ -977,6 +977,21 @@ def fixture_record(fixture_name, indexer: @indexer) end end + describe 'lc_facet' do + it 'includes a field with data for the classification facet' do + lc_facet = @sample40['lc_facet'] + expect(lc_facet).to match_array(['R - Medicine', 'R - Medicine:RA - Public Aspects of Medicine']) + end + it 'handles cases where the call number is a single letter' do + lc_facet = @sample44['lc_facet'] + expect(lc_facet).to match_array(['Z - Bibliography, Library Science, Information Resources', 'Z - Bibliography, Library Science, Information Resources:Z - Bibliography, Library Science, Information Resources']) + end + it 'handles cases where there is no call number' do + lc_facet = @record_no_call_number['lc_facet'] + expect(lc_facet).to be_nil + end + end + describe 'series 490 dedup, non-filing' do let(:s490) { { "490" => { "ind1" => "", "ind2" => " ", "subfields" => [{ "a" => "Series title" }] } } } let(:s830) { { "830" => { "ind1" => "", "ind2" => " ", "subfields" => [{ "a" => "Series title." }] } } } From 224c1ebf898e8e7d8f989dc8b92bad885268eea9 Mon Sep 17 00:00:00 2001 From: Ryan Laddusaw Date: Thu, 7 Nov 2024 13:09:54 -0500 Subject: [PATCH 2/4] Rubocop --- marc_to_solr/lib/traject_config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/marc_to_solr/lib/traject_config.rb b/marc_to_solr/lib/traject_config.rb index 0023ad45..7f502aa0 100644 --- a/marc_to_solr/lib/traject_config.rb +++ b/marc_to_solr/lib/traject_config.rb @@ -978,7 +978,7 @@ first_letter = record['050']['a'].lstrip.slice(0, 1) letters = /([[:alpha:]])*/.match(record['050']['a'])[0] accumulator << Traject::TranslationMap.new("callnumber_map")[first_letter] - accumulator << "#{Traject::TranslationMap.new("callnumber_map")[first_letter]}:#{Traject::TranslationMap.new("callnumber_map")[letters]}" + accumulator << "#{Traject::TranslationMap.new('callnumber_map')[first_letter]}:#{Traject::TranslationMap.new('callnumber_map')[letters]}" end end end From eaa24e21a6df03ea0d0c9011b042c2dc44849a56 Mon Sep 17 00:00:00 2001 From: rladdusaw Date: Tue, 12 Nov 2024 11:14:47 -0500 Subject: [PATCH 3/4] Use dig to reduce nested if statements Co-authored-by: Max Kadel --- marc_to_solr/lib/traject_config.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/marc_to_solr/lib/traject_config.rb b/marc_to_solr/lib/traject_config.rb index 7f502aa0..d44b7c4c 100644 --- a/marc_to_solr/lib/traject_config.rb +++ b/marc_to_solr/lib/traject_config.rb @@ -973,13 +973,11 @@ end to_field 'lc_facet' do |record, accumulator| - if record['050'] - if record['050']['a'] - first_letter = record['050']['a'].lstrip.slice(0, 1) - letters = /([[:alpha:]])*/.match(record['050']['a'])[0] - accumulator << Traject::TranslationMap.new("callnumber_map")[first_letter] - accumulator << "#{Traject::TranslationMap.new('callnumber_map')[first_letter]}:#{Traject::TranslationMap.new('callnumber_map')[letters]}" - end + if record.dig('050', 'a') + first_letter = record['050']['a'].lstrip.slice(0, 1) + letters = /([[:alpha:]])*/.match(record['050']['a'])[0] + accumulator << Traject::TranslationMap.new("callnumber_map")[first_letter] + accumulator << "#{Traject::TranslationMap.new('callnumber_map')[first_letter]}:#{Traject::TranslationMap.new('callnumber_map')[letters]}" end end From deddf53c4baeadd8bfa10a5e53d9500aa9e485ac Mon Sep 17 00:00:00 2001 From: Ryan Laddusaw Date: Tue, 12 Nov 2024 12:21:47 -0500 Subject: [PATCH 4/4] Revert "Use dig to reduce nested if statements" This reverts commit eaa24e21a6df03ea0d0c9011b042c2dc44849a56. --- marc_to_solr/lib/traject_config.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/marc_to_solr/lib/traject_config.rb b/marc_to_solr/lib/traject_config.rb index d44b7c4c..7f502aa0 100644 --- a/marc_to_solr/lib/traject_config.rb +++ b/marc_to_solr/lib/traject_config.rb @@ -973,11 +973,13 @@ end to_field 'lc_facet' do |record, accumulator| - if record.dig('050', 'a') - first_letter = record['050']['a'].lstrip.slice(0, 1) - letters = /([[:alpha:]])*/.match(record['050']['a'])[0] - accumulator << Traject::TranslationMap.new("callnumber_map")[first_letter] - accumulator << "#{Traject::TranslationMap.new('callnumber_map')[first_letter]}:#{Traject::TranslationMap.new('callnumber_map')[letters]}" + if record['050'] + if record['050']['a'] + first_letter = record['050']['a'].lstrip.slice(0, 1) + letters = /([[:alpha:]])*/.match(record['050']['a'])[0] + accumulator << Traject::TranslationMap.new("callnumber_map")[first_letter] + accumulator << "#{Traject::TranslationMap.new('callnumber_map')[first_letter]}:#{Traject::TranslationMap.new('callnumber_map')[letters]}" + end end end