Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/helpers/record_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def date_range(range)
end

def publication_date(metadata)
metadata['dates'].select { |date| date['kind'] == 'Publication date' }.first['value']
metadata[:dates].select { |date| date['kind'] == 'Publication date' }.first['value']
end

# Display the machine-format key in human-readable text.
Expand Down
14 changes: 7 additions & 7 deletions app/helpers/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ def displayed_fields
end

def trim_highlights(result)
return unless result['highlight']&.any?
return unless result[:highlight]&.any?

result['highlight'].reject { |h| displayed_fields.include? h['matchedField'] }
result[:highlight].reject { |h| displayed_fields.include? h['matchedField'] }
end

def format_highlight_label(field_name)
Expand All @@ -15,17 +15,17 @@ def format_highlight_label(field_name)
end

def link_to_result(result)
if result['source_link'].present?
link_to(result['title'], result['source_link'])
if result[:source_link].present?
link_to(result[:title], result[:source_link])
else
result['title']
result[:title]
end
end

def view_online(result)
return unless result['source_link'].present?
return unless result[:source_link].present?

link_to 'View online', result['source_link'], class: 'button button-primary'
link_to 'View online', result[:source_link], class: 'button button-primary'
end

def view_record(record_id)
Expand Down
54 changes: 27 additions & 27 deletions app/models/normalize_primo_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ def initialize(record, query)
def normalize
{
# Core fields
'title' => title,
'creators' => creators,
'source' => source,
'year' => year,
'format' => format,
'links' => links,
'citation' => citation,
'identifier' => record_id,
'summary' => summary,
'publisher' => publisher,
'location' => best_location,
'subjects' => subjects,
title:,
creators:,
source:,
year:,
format:,
links:,
citation:,
identifier:,
summary:,
publisher:,
location:,
subjects:,
# Primo-specific fields
'container' => container_title,
'numbering' => numbering,
'chapter_numbering' => chapter_numbering,
'thumbnail' => thumbnail,
'availability' => best_availability,
'other_availability' => other_availability?
container:,
numbering:,
chapter_numbering:,
thumbnail:,
availability:,
other_availability:
}
end

Expand Down Expand Up @@ -115,7 +115,7 @@ def citation
end
end

def container_title
def container
return unless @record['pnx']['addata']

if @record['pnx']['addata']['jtitle'].present?
Expand All @@ -125,7 +125,7 @@ def container_title
end
end

def record_id
def identifier
return unless @record['pnx']['control']['recordid']

@record['pnx']['control']['recordid'].join
Expand Down Expand Up @@ -224,7 +224,7 @@ def openurl
if openurl_server == record_openurl_server
construct_primo_openurl
else
Rails.logger.warn "Alma openurl server mismatch. Expected #{openurl_server}, but received #{record_openurl_server}. (record ID: #{record_id})"
Rails.logger.warn "Alma openurl server mismatch. Expected #{openurl_server}, but received #{record_openurl_server}. (record ID: #{identifier})"
@record['delivery']['almaOpenurl']
end
end
Expand Down Expand Up @@ -265,7 +265,7 @@ def publisher
@record['pnx']['addata']['pub'].first
end

def best_location
def location
return unless @record['delivery']
return unless @record['delivery']['bestlocation']

Expand All @@ -279,13 +279,13 @@ def subjects
@record['pnx']['display']['subject']
end

def best_availability
return unless best_location
def availability
return unless location

@record['delivery']['bestlocation']['availabilityStatus']
end

def other_availability?
def other_availability
return unless @record['delivery']['bestlocation']
return unless @record['delivery']['holding']

Expand All @@ -302,9 +302,9 @@ def frbrized?
end

def alma_record?
return false unless record_id
return false unless identifier

record_id.start_with?('alma')
identifier.start_with?('alma')
end

def dedup_url
Expand Down
34 changes: 17 additions & 17 deletions app/models/normalize_timdex_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ def initialize(record, query)
def normalize
{
# Core fields
'title' => title,
'creators' => creators,
'source' => source,
'year' => year,
'format' => format,
'links' => links,
'citation' => citation,
'identifier' => identifier,
'summary' => summary,
'publisher' => publisher,
'location' => location,
'subjects' => subjects,
title:,
creators:,
source:,
year:,
format:,
links:,
citation:,
identifier:,
summary:,
publisher:,
location:,
subjects:,
# TIMDEX-specific fields
'content_type' => content_type,
'dates' => dates,
'contributors' => contributors,
'highlight' => highlight,
'source_link' => source_link
content_type:,
dates:,
contributors:,
highlight:,
source_link:
}
end

Expand Down
6 changes: 3 additions & 3 deletions app/views/search/_result.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
</h3>

<p class="pub-info">
<span><%= result['content_type']&.each { |type| type['value'] }&.join(' ; ') %></span>
<span><%= result[:content_type]&.each { |type| type['value'] }&.join(' ; ') %></span>
<span>
<% result['dates']&.each do |date| %>
<% result[:dates]&.each do |date| %>
<%= date['value'] if date['kind'] == 'Publication date' %>
<% end %>
</span>
</p>

<span class="sr">Contributors: </span>
<ul class="list-inline truncate-list contributors">
<%= render partial: 'shared/contributors', locals: { contributors: result['contributors'] } %>
<%= render partial: 'shared/contributors', locals: { contributors: result[:contributors] } %>
</ul>

<div class="result-highlights">
Expand Down
16 changes: 8 additions & 8 deletions app/views/search/_result_geo.html.erb
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
<li class="result">
<div class="result-content">
<h3 class="record-title">
<span class="sr">Title: </span><%= link_to(result_geo['title'], record_path(result_geo['identifier'])) %>
<span class="sr">Title: </span><%= link_to(result_geo[:title], record_path(result_geo[:identifier])) %>
</h3>

<div class="data-info">
<%= render partial: 'shared/geo_data_info', locals: { metadata: result_geo } %>
</div>

<% if result_geo['creators'].present? || result_geo['contributors'].present? %>
<% if result_geo[:creators].present? || result_geo[:contributors].present? %>
<span class="sr">Contributors: </span>
<ul class="list-inline truncate-list contributors">
<!-- Use normalized creators if available, otherwise fall back to raw contributors -->
<% contributors = result_geo['creators'].present? ? result_geo['creators'] : result_geo['contributors'] %>
<% contributors = result_geo[:creators].present? ? result_geo[:creators] : result_geo[:contributors] %>
<% if contributors %>
<%= render partial: 'shared/contributors', locals: { contributors: contributors } %>
<% end %>
</ul>
<% end %>

<% if result_geo['summary'].present? %>
<% if result_geo[:summary].present? %>
<p class="result-summary truncate-list">
<span class="sr">Summary: </span><%= result_geo['summary'] %>
<span class="sr">Summary: </span><%= result_geo[:summary] %>
</p>
<% end %>

<% if result_geo['highlight'] %>
<% if result_geo[:highlight] %>
<div class="result-highlights">
<%= render partial: 'search/highlights', locals: { result: { 'highlight' => result_geo['highlight'] } } %>
<%= render partial: 'search/highlights', locals: { result: { highlight: result_geo[:highlight] } } %>
</div>
<% end %>

<div class="result-record">
<%= view_record(result_geo['identifier']) %>
<%= view_record(result_geo[:identifier]) %>
</div>
</div>
</li>
18 changes: 9 additions & 9 deletions app/views/search/_result_primo.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
<div class="result-content">
<h3 class="record-title">
<span class="sr">Title: </span>
<% if result['links']&.find { |link| link['kind'] == 'full record' } %>
<%= link_to(result['title'], result['links'].find { |link| link['kind'] == 'full record' }['url']) %>
<% if result[:links]&.find { |link| link['kind'] == 'full record' } %>
<%= link_to(result[:title], result[:links].find { |link| link['kind'] == 'full record' }['url']) %>
<% else %>
<%= result['title'] %>
<%= result[:title] %>
<% end %>
</h3>

<p class="pub-info">
<span><%= result['format'] %></span>
<span><%= result['year'] %></span>
<span><%= result[:format] %></span>
<span><%= result[:year] %></span>
</p>

<% if result['creators'].present? %>
<% if result[:creators].present? %>
<span class="sr">Contributors: </span>
<ul class="list-inline truncate-list contributors">
<% result['creators'].each do |creator| %>
<% result[:creators].each do |creator| %>
<li>
<% if creator[:link] %>
<%= link_to creator[:value], creator[:link] %>
Expand All @@ -30,8 +30,8 @@
<% end %>

<div class="result-get">
<% if result['links'].present? %>
<% result['links'].each do |link| %>
<% if result[:links].present? %>
<% result[:links].each do |link| %>
<%= link_to link['kind'].titleize, link['url'], class: 'link-button' %>
<% end %>
<% end %>
Expand Down
13 changes: 10 additions & 3 deletions app/views/shared/_geo_data_info.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<ul class="list-inline">
<li><%= metadata['contentType']&.each { |type| type['value'] }&.join(' ; ') %></li>
<% if parse_geo_dates(metadata['dates']) %>
<% if metadata[:content_type] %>
<li><%= metadata[:content_type]&.each { |type| type['value'] }&.join(' ; ') %></li>
<% elsif metadata['contentType'] %>
<li><%= metadata['contentType']&.each { |type| type['value'] }&.join(' ; ') %></li>
<% end %>

<% if parse_geo_dates(metadata[:dates]) %>
<li><%= parse_geo_dates(metadata[:dates]) %></li>
<% elsif parse_geo_dates(metadata['dates']) %>
<li><%= parse_geo_dates(metadata['dates']) %></li>
<% end %>
<% if access_type(metadata) == 'unknown: check with owning institution' %>
Expand All @@ -11,4 +18,4 @@
<% elsif access_type(metadata) == 'MIT authentication required' %>
<li><span class="access-restricted"><%= access_type(metadata) %></span></li>
<% end %>
</ul>
</ul>
10 changes: 5 additions & 5 deletions test/controllers/search_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
def mock_primo_search_success
# Mock the Primo search components to avoid external API calls
sample_doc = {
'title' => 'Sample Primo Document Title',
'format' => 'Article',
'year' => '2025',
'creators' => [
title: 'Sample Primo Document Title',
format: 'Article',
year: '2025',
creators: [
{ value: 'Foo Barston', link: nil },
{ value: 'Baz Quxley', link: nil }
],
'links' => [{ 'kind' => 'full record', 'url' => 'https://example.com/record' }]
links: [{ 'kind' => 'full record', 'url' => 'https://example.com/record' }]
}

mock_primo = mock('primo_search')
Expand Down
Loading