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

Expanded shelfkeys to include additional information #679

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
13 changes: 1 addition & 12 deletions lib/call_numbers/call_number_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CallNumberBase
LOOSE_MONTHS_REGEX = /([\.:\/\(])? *#{MONTHS}/i

extend Forwardable
delegate %i[to_shelfkey to_reverse_shelfkey] => :shelfkey
delegate %i[to_shelfkey] => :shelfkey

def scheme
raise NotImplementedError
Expand All @@ -31,17 +31,6 @@ def to_lopped_shelfkey
self.class.new(lopped, serial: serial).to_shelfkey
end

def to_lopped_reverse_shelfkey
if lopped == call_number
self.class.new(lopped, serial: serial).to_reverse_shelfkey
else
# Explicitly passing in the ellipsis (as it needs to be reversed)
# and dropping the serial since it has already been lopped
self.class.new("#{lopped} ...").to_reverse_shelfkey
end

end

def to_volume_sort
to_shelfkey
end
Expand Down
8 changes: 0 additions & 8 deletions lib/call_numbers/other.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ def to_lopped_shelfkey
self.class.new(lopped, serial: serial, scheme: scheme).to_shelfkey
end

def to_lopped_reverse_shelfkey
self.class.new(lopped, serial: serial, scheme: scheme).to_reverse_shelfkey
end

def lopped
return call_number if longest_common_prefix.empty? || longest_common_prefix =~ /^(mcd|mdvd|zdvd|mfilm|mfiche)$/i

Expand All @@ -48,10 +44,6 @@ def to_shelfkey
[shelfkey_scheme, CallNumbers::ShelfkeyBase.pad_all_digits(call_number)].join(' ')
end

def to_reverse_shelfkey
CallNumbers::ShelfkeyBase.reverse(to_shelfkey).ljust(50, '~')
end

private

# this transfomation only applies when generating shelfkeys
Expand Down
4 changes: 0 additions & 4 deletions lib/call_numbers/shelfkey_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ def to_shelfkey
raise NotImplementedError
end

def to_reverse_shelfkey
self.class.reverse(to_shelfkey).ljust(50, '~')
end

class << self
def reverse(value)
value.chars.map do |char|
Expand Down
88 changes: 33 additions & 55 deletions lib/traject/config/sirsi_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1913,55 +1913,6 @@ def holdings(record, context)
accumulator.select! { |cn| cn =~ SirsiHolding::CallNumber::VALID_LC_REGEX }
end

# shelfkey = custom, getShelfkeys

to_field 'shelfkey' do |record, accumulator, context|
holdings(record, context).each do |holding|
next if holding.skipped? || holding.shelved_by_location? || holding.lost_or_missing?
non_skipped_or_ignored_holdings = context.clipboard[:non_skipped_or_ignored_holdings_by_library_location_call_number_type]

stuff_in_the_same_library = Array(non_skipped_or_ignored_holdings[[holding.library, LOCATION_MAP[holding.home_location], holding.call_number_type]])

if stuff_in_the_same_library.length > 1
call_number_object = call_number_for_holding(record, holding, context)
lopped_shelfkey = call_number_object.to_lopped_shelfkey

# if we lopped the shelfkey, or if there's other stuff in the same library whose shelfkey will be lopped to this holding's shelfkey, we need to add ellipses.
if lopped_shelfkey != call_number_object.to_shelfkey || stuff_in_the_same_library.reject { |x| x.call_number.to_s == holding.call_number.to_s }.select { |x| call_number_for_holding(record, x, context).lopped == call_number_object.lopped }.any?
accumulator << lopped_shelfkey + " ..."
else
accumulator << lopped_shelfkey
end
else
accumulator << call_number_for_holding(record, holding, context).to_shelfkey
end
end
end

# given a shelfkey (a lexicaly sortable call number), return the reverse
# shelf key - a sortable version of the call number that will give the
# reverse order (for getting "previous" call numbers in a list)
#
# return the reverse String value, mapping A --> 9, B --> 8, ...
# 9 --> A and also non-alphanum to sort properly (before or after alphanum)
to_field 'reverse_shelfkey' do |record, accumulator, context|
holdings(record, context).each do |holding|
next if holding.skipped? || holding.shelved_by_location? || holding.lost_or_missing?
non_skipped_or_ignored_holdings = context.clipboard[:non_skipped_or_ignored_holdings_by_library_location_call_number_type]

stuff_in_the_same_library = Array(non_skipped_or_ignored_holdings[[holding.library, LOCATION_MAP[holding.home_location], holding.call_number_type]])

if stuff_in_the_same_library.length > 1
call_number_object = call_number_for_holding(record, holding, context)
lopped_shelfkey = call_number_object.to_lopped_reverse_shelfkey

accumulator << lopped_shelfkey
else
accumulator << call_number_for_holding(record, holding, context).to_reverse_shelfkey
end
end
end

#
# # Location facet
to_field 'location_facet', extract_marc('852c:999l') do |record, accumulator|
Expand Down Expand Up @@ -2217,6 +2168,7 @@ def holdings(record, context)
end

to_field 'item_display' do |record, accumulator, context|
shelfkey_global_sort = "#{(context.output_hash['title_sort']&.first || '')[0..6].ljust(6, '~')}/#{(context.output_hash['pub_date_sort']&.first || '').ljust(6, '~')}/#{context.output_hash['id']}"
holdings(record, context).each do |holding|
next if holding.skipped?

Expand All @@ -2238,21 +2190,18 @@ def holdings(record, context)

enumeration = holding.call_number.to_s[call_number_object.lopped.length..-1].strip unless holding.ignored_call_number?
shelfkey = lopped_call_number.downcase
reverse_shelfkey = CallNumbers::ShelfkeyBase.reverse(shelfkey)

call_number = [lopped_call_number, (enumeration if enumeration)].compact.join(' ') unless holding.e_call_number?
volume_sort = [lopped_call_number, (CallNumbers::ShelfkeyBase.reverse(CallNumbers::ShelfkeyBase.pad_all_digits(enumeration)).ljust(50, '~') if enumeration)].compact.join(' ').downcase
# if there's only one item in a library/home_location/call_number_type, then we use the non-lopped versions of stuff
elsif stuff_in_the_same_library.length <= 1
shelfkey = call_number_object.to_shelfkey
volume_sort = call_number_object.to_volume_sort
reverse_shelfkey = call_number_object.to_reverse_shelfkey
lopped_call_number = call_number_object.call_number
else
# there's more than one item in the library/home_location/call_number_type, so we lop
shelfkey = call_number_object.to_lopped_shelfkey == call_number_object.to_shelfkey ? call_number_object.to_shelfkey : "#{call_number_object.to_lopped_shelfkey} ..."
volume_sort = call_number_object.to_volume_sort
reverse_shelfkey = call_number_object.to_lopped_reverse_shelfkey
lopped_call_number = call_number_object.lopped == holding.call_number.to_s ? holding.call_number.to_s : "#{call_number_object.lopped} ..."

# if we lopped the shelfkey, or if there's other stuff in the same library whose shelfkey will be lopped to this holding's shelfkey, we need to add ellipses.
Expand All @@ -2265,10 +2214,14 @@ def holdings(record, context)
scheme = ''
shelfkey = ''
volume_sort = ''
reverse_shelfkey = ''
lopped_call_number = holding.call_number.to_s
end

shelfkey = '' if holding.lost_or_missing?
shelfkey ||= ''

shelfkey = "#{shelfkey}/#{shelfkey_global_sort}" unless shelfkey.empty?

current_location = holding.current_location
current_location = 'ON-ORDER' if holding.is_on_order? && holding.current_location && !holding.current_location.empty? && holding.home_location != 'ON-ORDER' && holding.home_location != 'INPROCESS'

Expand All @@ -2279,8 +2232,8 @@ def holdings(record, context)
current_location,
holding.type,
(lopped_call_number unless holding.ignored_call_number? && !holding.shelved_by_location?),
(shelfkey unless holding.lost_or_missing?),
(reverse_shelfkey.ljust(50, '~') if reverse_shelfkey && !reverse_shelfkey.empty? && !holding.lost_or_missing?),
shelfkey,
(CallNumbers::ShelfkeyBase.reverse(shelfkey).ljust(50, '~') unless shelfkey.empty?),
(call_number unless holding.ignored_call_number? && !holding.shelved_by_location?) || (call_number if holding.e_call_number? && call_number.to_s != SirsiHolding::ECALLNUM && !call_number_object.call_number),
(volume_sort unless holding.ignored_call_number? && !holding.shelved_by_location?),
holding.public_note,
Expand Down Expand Up @@ -2311,6 +2264,31 @@ def holdings(record, context)
end
end


# shelfkey = custom, getShelfkeys

to_field 'shelfkey' do |record, accumulator, context|
shelfkeys = (context.output_hash['item_display'] || []).map do |item_display|
item_display.split(' -|- ')[6]
end

accumulator.concat shelfkeys.compact.reject(&:empty?)
end

# given a shelfkey (a lexicaly sortable call number), return the reverse
# shelf key - a sortable version of the call number that will give the
# reverse order (for getting "previous" call numbers in a list)
#
# return the reverse String value, mapping A --> 9, B --> 8, ...
# 9 --> A and also non-alphanum to sort properly (before or after alphanum)
to_field 'reverse_shelfkey' do |record, accumulator, context|
shelfkeys = (context.output_hash['item_display'] || []).map do |item_display|
item_display.split(' -|- ')[7]
end

accumulator.concat shelfkeys.compact.reject(&:empty?)
end

##
# Skip records for missing `item_display` field
each_record do |record, context|
Expand Down
12 changes: 0 additions & 12 deletions spec/lib/call_numbers/other_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@
end
end

describe '#to_reverse_shelfkey' do
before { I18n.config.available_locales = :en } # No idea why this is needed
let(:reverse_shelfkey) { described_class.new('ZDVD 1234').to_reverse_shelfkey }

it 'uses CallNumbers::Shelfkey.reverse to reverse' do
expect(reverse_shelfkey).to start_with('b6il8')
expect(reverse_shelfkey).to include('0m4m')
expect(reverse_shelfkey).to include('zzyxwv')
expect(reverse_shelfkey).to end_with('~~~')
end
end

describe '#shelfkey_scheme' do
it 'is "sudoc" when "SUDOC" is passed' do
expect(described_class.new('ZDVD 1234', scheme: 'SUDOC').to_shelfkey).to start_with 'sudoc'
Expand Down
18 changes: 17 additions & 1 deletion spec/lib/traject/config/course_reserves_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,23 @@
let(:fixture_name) { '444.marc' }
let(:field) { 'item_display' }
it 'updates item_display with crez info' do
expect(result[field]).to eq ['36105041844338 -|- MUSIC -|- SCORES -|- GREEN-RESV -|- SCORE -|- M1048 .B41 C7 1973 -|- lc m 1048.000000 b0.410000 c0.700000 001973 -|- en~d~~~yzvr}zzzzzz~oz}vyzzzz~nz}szzzzz~zzyqsw~~~~~ -|- M1048 .B41 C7 1973 -|- lc m 1048.000000 b0.410000 c0.700000 001973 -|- -|- LC -|- AMSTUD-214 -|- GREEN-RESV -|- 2-hour loan']
expect(result[field].first.split(' -|- ')).to contain_exactly(
'36105041844338',
'MUSIC',
'SCORES',
'GREEN-RESV',
'SCORE',
'M1048 .B41 C7 1973',
start_with('lc'),
start_with('en'),
'M1048 .B41 C7 1973',
start_with('lc'),
'',
'LC',
'AMSTUD-214',
'GREEN-RESV',
'2-hour loan'
)
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/lib/traject/config/item_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@
'',
'',
'Shelved by title',
'shelved by title',
start_with('shelved by title'),
/~~~/,
'Shelved by title VOL 1 1946',
/shelved by title/,
Expand Down Expand Up @@ -394,7 +394,7 @@
'',
'',
'Shelved by title',
'shelved by title',
start_with('shelved by title'),
/~~~/,
'Shelved by title V.3 1986 MAY-AUG.',
/shelved by title/,
Expand Down