Skip to content

Commit

Permalink
Merge pull request #63 from scientist-softserv/add-data-to-test-year-…
Browse files Browse the repository at this point in the history
…facet

⚙️ Bring over `year_range` from `ngao`
  • Loading branch information
sjproctor authored Sep 3, 2024
2 parents e3b468c + 1d995df commit 0564f7e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/arclight/traject/ead2_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
require 'active_model/conversion' ## Needed for Arclight::Repository
require 'active_support/core_ext/array/wrap'
require 'arclight/digital_object'
require 'arclight/year_range'
# IU customization: allow for collection date ranges over 1,000 years
require_relative '../../ngao/year_range'
require 'arclight/repository'
require 'arclight/traject/nokogiri_namespaceless_reader'
require 'debug' ## Needed for debugging
Expand Down Expand Up @@ -230,7 +231,7 @@
to_field 'genreform_ssim', extract_xpath('/ead/archdesc/controlaccess/genreform')

to_field 'date_range_isim', extract_xpath('/ead/archdesc/did/unitdate/@normal', to_text: false) do |_record, accumulator|
range = Arclight::YearRange.new
range = ::Ngao::YearRange.new
next range.years if accumulator.blank?

ranges = accumulator.map(&:to_s)
Expand Down
21 changes: 21 additions & 0 deletions lib/ngao/year_range.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require 'arclight/year_range'

module Ngao
class YearRange < Arclight::YearRange
# @param [String] `dates` in the form YYYY/YYYY
# @return [Array<Integer>] the set of years in the given range
def parse_range(dates)
return if dates.blank?

start_year, end_year = dates.split('/').map { |date| to_year_from_iso8601(date) }
return [start_year] if end_year.blank?
# Original in Arclight checks that date ranges can't be larger than 1000 years, we don't want that in NGAO
# raise ArgumentError, "Range is too large: #{dates}" if (end_year - start_year) > 1000
raise ArgumentError, "Range is inverted: #{dates}" unless start_year <= end_year

(start_year..end_year).to_a
end
end
end

0 comments on commit 0564f7e

Please sign in to comment.