@@ -24,6 +24,7 @@ def normalize
2424 subjects :,
2525 # TIMDEX-specific fields
2626 content_type :,
27+ date_range :,
2728 dates :,
2829 contributors :,
2930 highlight :,
@@ -34,7 +35,26 @@ def normalize
3435 private
3536
3637 def title
37- @record [ 'title' ] || 'Unknown title'
38+ title = @record [ 'title' ] || 'Unknown title'
39+
40+ # The collection identifier is important for ASpace records so we append it to the title
41+ return title unless source == 'MIT ArchivesSpace'
42+
43+ title += " (#{ aspace_collection ( @record [ 'identifiers' ] ) } )"
44+ end
45+
46+ def aspace_collection ( identifiers )
47+ relevant_ids = identifiers . map { |id | id [ 'value' ] if id [ 'kind' ] == 'Collection Identifier' } . compact
48+
49+ # In the highly unlikely event that there is more than one collection identifier, there's something weird going
50+ # on with the record and we should look into it.
51+ if relevant_ids . count > 1
52+ Sentry . set_tags ( 'mitlib.recordId' : identifier || 'empty record id' )
53+ Sentry . set_tags ( 'mitlib.collection_ids' : relevant_ids . join ( '; ' ) )
54+ Sentry . capture_message ( 'Multiple Collection IDs found in ASpace record' )
55+ end
56+
57+ relevant_ids . first
3858 end
3959
4060 def creators
@@ -104,7 +124,7 @@ def links
104124 end
105125
106126 def citation
107- @record [ 'citation' ] || nil
127+ @record [ 'citation' ]
108128 end
109129
110130 def summary
@@ -130,7 +150,7 @@ def location
130150 def subjects
131151 return [ ] unless @record [ 'subjects' ]
132152
133- @record [ 'subjects' ] . map { |subject | subject [ 'value' ] }
153+ @record [ 'subjects' ] . flat_map { |subject | subject [ 'value' ] }
134154 end
135155
136156 def identifier
@@ -146,6 +166,25 @@ def dates
146166 @record [ 'dates' ]
147167 end
148168
169+ def date_range
170+ return unless @record [ 'dates' ]
171+
172+ # Some records have creation or publication dates that are ranges. Extract those here.
173+ relevant_dates = @record [ 'dates' ] . select do |date |
174+ %w[ creation publication ] . include? ( date [ 'kind' ] ) && date [ 'range' ] . present?
175+ end
176+
177+ # If the record has no creation or publication date, stop here.
178+ return if relevant_dates . empty?
179+
180+ # If the record *does* have more than one creation/pub date, just take the first one. Note: ASpace records often
181+ # have more than one. Sometimes they are duplicates, sometimes they are different. For now we will just take the
182+ # first.
183+ relevant_date = relevant_dates . first
184+
185+ "#{ relevant_date [ 'range' ] [ 'gte' ] } -#{ relevant_date [ 'range' ] [ 'lte' ] } "
186+ end
187+
149188 def contributors
150189 @record [ 'contributors' ]
151190 end
0 commit comments