From b6ea0cf36f52daf06c8b84e9acb938c1bc098228 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Mon, 21 Oct 2024 14:12:47 -0700 Subject: [PATCH 1/9] WIP --- app/controllers/catalog_controller.rb | 10 +++++----- app/helpers/shared_search_helper.rb | 2 +- app/views/catalog/_index_header_list_default.html.erb | 11 ++++++++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index fce3e9b09..e997923b1 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -41,7 +41,11 @@ def self.uploaded_field # IiifPrint index fields config.add_index_field 'all_text_timv' - config.add_index_field 'all_text_tsimv', label: "Item contents", highlight: true, helper_method: :render_ocr_snippets, if: :query_present? + config.add_index_field 'all_text_tsimv', + label: "Item contents", + highlight: true, + helper_method: :render_ocr_snippets, + values: ->(field_config, document, _context) { document.highlight_field(field_config.field).map(&:html_safe) if document.has_highlight_field? field_config.field } # configuration for Blacklight IIIF Content Search config.iiif_search = { @@ -638,9 +642,5 @@ def show def render_bookmarks_control? false end - - def query_present? - params[:q].present? - end end # rubocop:enable Metrics/ClassLength, Metrics/BlockLength diff --git a/app/helpers/shared_search_helper.rb b/app/helpers/shared_search_helper.rb index 0c5a6b370..e2131ba23 100644 --- a/app/helpers/shared_search_helper.rb +++ b/app/helpers/shared_search_helper.rb @@ -19,7 +19,7 @@ def generate_work_url(model, request) url = get_url(id:, request: request_params, account_cname:, base_route_name:) # pass search query params to work show page - params[:q].present? ? "#{url}?q=#{params[:q]}" : url + (params[:q].present? && params[:highlight]) ? "#{url}?q=#{params[:q]}" : url end private diff --git a/app/views/catalog/_index_header_list_default.html.erb b/app/views/catalog/_index_header_list_default.html.erb index 000176cd9..379c172e9 100644 --- a/app/views/catalog/_index_header_list_default.html.erb +++ b/app/views/catalog/_index_header_list_default.html.erb @@ -1,6 +1,15 @@ <%# OVERRIDE Hyrax v5.0.1 to collection badge and markdown of links %>
-

<%= link_to markdown(document.title_or_label), generate_work_url(document, request) %>

+

+ <% if params['q'].present? && document.any_highlighting_in_all_text_fields? %> + <%= link_to document.title_or_label, [document, { parent_query: params['q'], highlight: 'true' }] %>

+ <% elsif params['q'].present? %> + <%= link_to document.title_or_label, [document, { query: params['q'] }] %> + <% else %> + <%= link_to document.title_or_label, document %> + <% end %> + + <% if document.hydra_model == Hyrax.config.collection_class || document.hydra_model < Hyrax.config.collection_class %> <%= Hyrax::CollectionPresenter.new(document, current_ability).collection_type_badge %> <% end %> From e548cd22d7ac42fc8d11f334083519d04228cdac Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Mon, 21 Oct 2024 15:48:51 -0700 Subject: [PATCH 2/9] :bug: Add check to prevent displaying blank metadata --- app/views/catalog/_index_list_default.html.erb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/catalog/_index_list_default.html.erb b/app/views/catalog/_index_list_default.html.erb index 39329f4be..dd935e223 100644 --- a/app/views/catalog/_index_list_default.html.erb +++ b/app/views/catalog/_index_list_default.html.erb @@ -1,12 +1,14 @@ <%# OVERRIDE Hyrax 5.0.1 to enable markdown for index field values in search results %> <%# OVERRIDE Hyrax 5.0.1 to handle search only accounts %> +<%# OVERRIDE Hyrax 5.0.1 display label only when a property has a value, to prevent blank metadata %>