Skip to content

Commit

Permalink
Merge pull request #1357 from sul-dlss/preferred-barcode
Browse files Browse the repository at this point in the history
Clean up preferred barcode fallback
  • Loading branch information
jcoyne authored Feb 23, 2024
2 parents cc0f56c + f4df9fc commit f9d186c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/traject/config/folio_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2166,21 +2166,22 @@ def accumulate_summary_struct_fields(matching_fields, tag, label, marc, accumula
accumulator << holding_with_the_most_recent_shelfkey.barcode
end

# In the first pass (above), we ignored items without a call number (e.g. e-resources, in-process items, etc).
# E-resources, in particular, sometimes have a call number in the MARC metadata that we can use to drive the
# browse behavior, so here we take a second pass through the records loosening some of the initial restrictions
# to try to select an item.
to_field 'preferred_barcode' do |record, accumulator, context|
next if context.output_hash['preferred_barcode']
next unless record['050'] || record['090'] || record['086']

non_skipped_holdings = []
holdings(record, context).each do |holding|
next if holding.skipped?

non_skipped_holdings << holding
non_skipped_holdings = holdings(record, context).sort_by(&:call_number).reject do |holding|
holding.skipped? || holding.bad_lc_lane_call_number?
end

online_locs = %w[E-RECVD E-RESV ELECTR-LOC INTERNET KIOST ONLINE-TXT RESV-URL WORKSTATN]
next if non_skipped_holdings.length == 0

preferred_holding = non_skipped_holdings.first do |holding|
ignored_call_number? || online_locs.include?(holding.display_location_code)
preferred_holding = non_skipped_holdings.find do |holding|
holding.ignored_call_number?
end

accumulator << preferred_holding.barcode if preferred_holding
Expand Down

0 comments on commit f9d186c

Please sign in to comment.