11# Transforms results from Primo Search API into normalized records
22class NormalizePrimo
3- def initialize ( record )
3+ def initialize ( record , query )
44 @record = record
5+ @query = query
56 end
67
78 def normalize
@@ -17,7 +18,13 @@ def normalize
1718 'identifier' => record_id ,
1819 'summary' => summary ,
1920 'numbering' => numbering ,
20- 'chapter_numbering' => chapter_numbering
21+ 'chapter_numbering' => chapter_numbering ,
22+ 'thumbnail' => thumbnail ,
23+ 'publisher' => publisher ,
24+ 'location' => best_location ,
25+ 'subjects' => subjects ,
26+ 'availability' => best_availability ,
27+ 'other_availability' => other_availability?
2128 }
2229 end
2330
@@ -78,8 +85,10 @@ def format
7885 def links
7986 links = [ ]
8087
81- # Add direct record link as the first link
82- if record_link . present?
88+ # Use dedup URL as the full record link if available, otherwise use record link
89+ if dedup_url . present?
90+ links << { 'url' => dedup_url , 'kind' => 'full record' }
91+ elsif record_link . present?
8392 links << { 'url' => record_link , 'kind' => 'full record' }
8493 end
8594
@@ -176,12 +185,6 @@ def chapter_numbering
176185 "#{ @record [ 'pnx' ] [ 'addata' ] [ 'date' ] . join } , pp. #{ @record [ 'pnx' ] [ 'addata' ] [ 'pages' ] . join } "
177186 end
178187
179- def openurl
180- return unless @record [ 'delivery' ] && @record [ 'delivery' ] [ 'almaOpenurl' ]
181-
182- @record [ 'delivery' ] [ 'almaOpenurl' ] . is_a? ( Array ) ? @record [ 'delivery' ] [ 'almaOpenurl' ] . join : @record [ 'delivery' ] [ 'almaOpenurl' ]
183- end
184-
185188 def sanitize_authors ( authors )
186189 authors . map! { |author | author . split ( ';' ) } . flatten! if authors . any? { |author | author . include? ( ';' ) }
187190 authors . map { |author | author . strip . gsub ( /\$ \$ Q.*$/ , '' ) }
@@ -246,4 +249,68 @@ def construct_primo_openurl
246249 filtered = params . delete_if { |key , _value | key . starts_with? ( 'ctx' ) }
247250 URI ::DEFAULT_PARSER . unescape ( filtered . to_param )
248251 end
252+
253+ def thumbnail
254+ return unless @record [ 'pnx' ] [ 'addata' ] && @record [ 'pnx' ] [ 'addata' ] [ 'isbn' ]
255+
256+ # A record can have multiple ISBNs, so we are assuming here that
257+ # the thumbnail URL can be constructed from the first occurrence
258+ isbn = @record [ 'pnx' ] [ 'addata' ] [ 'isbn' ] . first
259+ [ ENV [ 'SYNDETICS_PRIMO_URL' ] , '&isbn=' , isbn , '/sc.jpg' ] . join
260+ end
261+
262+ def publisher
263+ return unless @record [ 'pnx' ] [ 'addata' ] && @record [ 'pnx' ] [ 'addata' ] [ 'pub' ]
264+ @record [ 'pnx' ] [ 'addata' ] [ 'pub' ] . first
265+ end
266+
267+ def best_location
268+ return unless @record [ 'delivery' ]
269+ return unless @record [ 'delivery' ] [ 'bestlocation' ]
270+ loc = @record [ 'delivery' ] [ 'bestlocation' ]
271+ [ "#{ loc [ 'mainLocation' ] } #{ loc [ 'subLocation' ] } " , loc [ 'callNumber' ] ]
272+ end
273+
274+ def subjects
275+ return [ ] unless @record [ 'pnx' ] [ 'display' ] [ 'subject' ]
276+ @record [ 'pnx' ] [ 'display' ] [ 'subject' ]
277+ end
278+
279+ def best_availability
280+ return unless best_location
281+ @record [ 'delivery' ] [ 'bestlocation' ] [ 'availabilityStatus' ]
282+ end
283+
284+ def other_availability?
285+ return unless @record [ 'delivery' ] [ 'bestlocation' ]
286+ return unless @record [ 'delivery' ] [ 'holding' ]
287+ @record [ 'delivery' ] [ 'holding' ] . length > 1
288+ end
289+
290+ # FRBR Group check based on:
291+ # https://knowledge.exlibrisgroup.com/Primo/Knowledge_Articles/Primo_Search_API_-_how_to_get_FRBR_Group_members_after_a_search
292+ def frbrized?
293+ return unless @record [ 'pnx' ] [ 'facets' ]
294+ return unless @record [ 'pnx' ] [ 'facets' ] [ 'frbrtype' ]
295+ @record [ 'pnx' ] [ 'facets' ] [ 'frbrtype' ] . join == '5'
296+ end
297+
298+ def dedup_url
299+ return unless frbrized?
300+ return unless @record [ 'pnx' ] [ 'facets' ] [ 'frbrgroupid' ] &&
301+ @record [ 'pnx' ] [ 'facets' ] [ 'frbrgroupid' ] . length == 1
302+
303+ frbr_group_id = @record [ 'pnx' ] [ 'facets' ] [ 'frbrgroupid' ] . join
304+ base = [ ENV [ 'MIT_PRIMO_URL' ] , '/discovery/search?' ] . join
305+
306+ query = {
307+ query : "any,contains,#{ @query } " ,
308+ tab : ENV [ 'PRIMO_TAB' ] ,
309+ search_scope : ENV [ 'PRIMO_SCOPE' ] ,
310+ sortby : 'date_d' ,
311+ vid : ENV [ 'PRIMO_VID' ] ,
312+ facet : "frbrgroupid,include,#{ frbr_group_id } "
313+ } . to_query
314+ [ base , query ] . join
315+ end
249316end
0 commit comments