From f9745a65a2e5739359da77532b24e1c5673ef2a8 Mon Sep 17 00:00:00 2001 From: rladdusaw Date: Tue, 12 Nov 2024 15:58:51 -0500 Subject: [PATCH] Index lc_facet field (#2547) * Index lc_facet field * Rubocop * Use dig to reduce nested if statements Co-authored-by: Max Kadel * Revert "Use dig to reduce nested if statements" This reverts commit eaa24e21a6df03ea0d0c9011b042c2dc44849a56. --------- Co-authored-by: Ryan Laddusaw Co-authored-by: Max Kadel --- 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..7f502aa0 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." }] } } }