From ac6b63cab6b4fc873a120fdcce3d4f873f33f39a Mon Sep 17 00:00:00 2001 From: cjcolvar Date: Fri, 12 Jul 2024 13:29:07 -0400 Subject: [PATCH 1/2] Don't show Found in if no found in hits exist --- app/views/catalog/_index_media_object.html.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/catalog/_index_media_object.html.erb b/app/views/catalog/_index_media_object.html.erb index 32c7bdf417..400f1360ec 100644 --- a/app/views/catalog/_index_media_object.html.erb +++ b/app/views/catalog/_index_media_object.html.erb @@ -23,8 +23,9 @@ Unless required by applicable law or agreed to in writing, software distributed
<%= field_presenter.values.join(', ') %>
<% end %> <% end %> - <% if params[:q].present? %> + <% found_in_hits = display_found_in(doc_presenter.document) %> + <% if params[:q].present? && found_in_hits.present? %>
Found in:
-
<%= display_found_in(doc_presenter.document) %>
+
<%= found_in_hits %>
<% end %> From 1906db68e5b47239b516755e437ac6d1fb5b5ebf Mon Sep 17 00:00:00 2001 From: cjcolvar Date: Fri, 12 Jul 2024 14:22:05 -0400 Subject: [PATCH 2/2] Only call display_found_in if q present; Fix case where no transcripts present in document --- app/helpers/catalog_helper.rb | 2 +- app/views/catalog/_index_media_object.html.erb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/helpers/catalog_helper.rb b/app/helpers/catalog_helper.rb index 8c83c6b424..ec884f12ca 100644 --- a/app/helpers/catalog_helper.rb +++ b/app/helpers/catalog_helper.rb @@ -23,7 +23,7 @@ def current_sort_field def display_found_in(document) metadata_count = document.to_h.sum {|k,v| k =~ /metadata_tf_/ ? v : 0 } - transcript_count = document["sections"]["docs"].sum { |d| d["transcripts"]["docs"].sum {|s| s.sum {|k,v| k =~ /transcript_tf_/ ? v : 0 }}} + transcript_count = document["sections"]["docs"].sum { |d| Array(d.dig("transcripts", "docs")).sum {|s| s.sum {|k,v| k =~ /transcript_tf_/ ? v : 0 }}} section_count = document.to_h.sum {|k,v| k =~ /structure_tf_/ ? v : 0 } metadata = "metadata (#{metadata_count})" if metadata_count > 0 diff --git a/app/views/catalog/_index_media_object.html.erb b/app/views/catalog/_index_media_object.html.erb index 400f1360ec..b76f1f3bbf 100644 --- a/app/views/catalog/_index_media_object.html.erb +++ b/app/views/catalog/_index_media_object.html.erb @@ -23,8 +23,7 @@ Unless required by applicable law or agreed to in writing, software distributed
<%= field_presenter.values.join(', ') %>
<% end %> <% end %> - <% found_in_hits = display_found_in(doc_presenter.document) %> - <% if params[:q].present? && found_in_hits.present? %> + <% if params[:q].present? && (found_in_hits = display_found_in(doc_presenter.document)).present? %>
Found in:
<%= found_in_hits %>
<% end %>