Skip to content

Commit

Permalink
Index lc_facet field (#2547)
Browse files Browse the repository at this point in the history
* Index lc_facet field

* Rubocop

* Use dig to reduce nested if statements

Co-authored-by: Max Kadel <[email protected]>

* Revert "Use dig to reduce nested if statements"

This reverts commit eaa24e2.

---------

Co-authored-by: Ryan Laddusaw <[email protected]>
Co-authored-by: Max Kadel <[email protected]>
  • Loading branch information
3 people authored Nov 12, 2024
1 parent 67c8a54 commit f9745a6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions marc_to_solr/lib/traject_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions spec/marc_to_solr/lib/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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." }] } } }
Expand Down

0 comments on commit f9745a6

Please sign in to comment.