@@ -24,7 +24,7 @@ def extract_results(results, norm)
2424 result_title = extract_title ( record )
2525 result = Result . new ( result_title , record [ 'sourceLink' ] )
2626 result . blurb = extract_first_from_list ( record [ 'summary' ] )
27- result . year = extract_field ( record [ 'publicationDate ' ] )
27+ result . year = extract_dates ( record [ 'dates ' ] )
2828 result . authors = extract_field ( extract_list ( record [ 'contributors' ] ) )
2929 result . physical_description = extract_field ( record [ 'physicalDescription' ] )
3030 norm [ 'results' ] << result
@@ -33,10 +33,36 @@ def extract_results(results, norm)
3333
3434 def extract_title ( record )
3535 title = record [ 'title' ]
36- title << ( " ( #{ record [ 'identifier' ] . to_s . gsub ( 'MIT:archivespace:' , '' ) } )" ) if record [ 'identifier ' ] . present?
36+ title << extract_collection_id ( record [ 'identifiers' ] ) if record [ 'identifiers ' ] . present?
3737 title
3838 end
3939
40+ def extract_dates ( dates )
41+ # It is unlikely for a record to have more than one creation date, but just in case...
42+ relevant_dates = dates . select { |date | date [ 'kind' ] == 'creation' }
43+
44+ # If the record *does* have more than one creation date, it's probably not worth determining which to display.
45+ return if relevant_dates . count > 1
46+
47+ relevant_date = relevant_dates . first
48+
49+ # We are only concerned with creation dates that are ranges, since we harvest ASpace metadata at the collection
50+ # level.
51+ return unless relevant_date [ 'kind' ] == 'creation' && relevant_date [ 'range' ] . present?
52+
53+ "#{ relevant_date [ 'range' ] [ 'gte' ] } -#{ relevant_date [ 'range' ] [ 'lte' ] } "
54+ end
55+
56+ def extract_collection_id ( identifiers )
57+ relevant_ids = identifiers . map { |id | id [ 'value' ] if id [ 'kind' ] == 'Collection Identifier' } . compact
58+
59+ # In the highly unlikely event that there is more than one collection identifier, there's something weird going
60+ # on with the record and we should skip it.
61+ return if relevant_ids . count > 1
62+
63+ " (#{ relevant_ids . first } )"
64+ end
65+
4066 def extract_list ( contributors )
4167 contributors &.map do |creator |
4268 [ creator [ 'value' ] , '&field[]=creators_text&q[]=' << URI . encode_www_form_component ( creator [ 'value' ] ) ]
0 commit comments