diff --git a/Gemfile.lock b/Gemfile.lock index 5e98235a8..9ad7af90b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -194,7 +194,7 @@ GIT GIT remote: https://github.com/scientist-softserv/iiif_print.git - revision: 02f68fc6d93b44b05d826b29645ef182534a51b5 + revision: 7f35ea9e5b4aedc55f2a6abd1dc5181bf9ed75ff branch: main specs: iiif_print (3.0.1) diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index fce3e9b09..bd7c75080 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 = { @@ -229,7 +233,7 @@ def self.uploaded_field all_names = config.show_fields.values.map(&:field).join(" ") title_name = 'title_tesim' field.solr_parameters = { - qf: "#{all_names} file_format_tesim all_text_timv", + qf: "#{all_names} file_format_tesim all_text_tsimv all_text_tsimv", pf: title_name.to_s } end @@ -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/hyku/blacklight_helper_behavior.rb b/app/helpers/hyku/blacklight_helper_behavior.rb index 91be4cd8a..c60a2509f 100644 --- a/app/helpers/hyku/blacklight_helper_behavior.rb +++ b/app/helpers/hyku/blacklight_helper_behavior.rb @@ -44,7 +44,7 @@ def link_to_document(doc, field_or_opts = nil, opts = { counter: nil }) # pull solr_document from input if we don't already have a solr_document document = doc&.try(:solr_document) || doc Deprecation.silence(Blacklight::UrlHelperBehavior) do - link_to label, generate_work_url(document, request), document_link_params(document, opts) + link_to label, generate_work_url(document, request, universal_viewer_url_params(opts)), document_link_params(document, opts) end end # rubocop:enable Metrics/MethodLength @@ -56,7 +56,13 @@ def link_to_document(doc, field_or_opts = nil, opts = { counter: nil }) # method `session_tracking_params`so that instead of a path we have a URL # @private def document_link_params(_doc, opts) - opts.except(:label, :counter) + opts.except(:label, :counter, :q, :highlight) + end + private :document_link_params + + # options needed to carry the search into the universalviewer + def universal_viewer_url_params(opts) + opts.slice(:q, :highlight) end private :document_link_params end diff --git a/app/helpers/shared_search_helper.rb b/app/helpers/shared_search_helper.rb index 0c5a6b370..4f3dc5d92 100644 --- a/app/helpers/shared_search_helper.rb +++ b/app/helpers/shared_search_helper.rb @@ -1,29 +1,83 @@ # frozen_string_literal: true +# A helper module that generates work URLs based on models and request parameters. module SharedSearchHelper - def generate_work_url(model, request) - # handle the various types of info we receive: + # Generates a URL for the given model with optional query parameters. + # + # @param model [Object] the model object, typically a work or collection + # @param request [ActionDispatch::Request] the current HTTP request object + # @param params [Hash] additional query parameters (e.g., search queries) + # @return [String] the generated URL with or without query parameters + def generate_work_url(model, request, params = {}) + id, base_route_name, account_cname = extract_model_info(model, request) + request_params = extract_request_params(request) + url = build_url(id, request_params, account_cname, base_route_name) + + append_query_params(url, model, params) + end + + private + + # Extracts the model ID, route name, and account cname from the model and request. + # + # @param model [Object] the model object (e.g., Hyrax::IiifAv::IiifFileSetPresenter or others) + # @param request [ActionDispatch::Request] the current HTTP request object + # @return [Array] a tuple containing the model's ID, route name, and account cname + def extract_model_info(model, request) if model.class == Hyrax::IiifAv::IiifFileSetPresenter base_route_name = model.model_name.plural id = model.id account_cname = request.server_name else model_hash = model.to_h.with_indifferent_access - base_route_name = model_hash["has_model_ssim"].first.constantize.model_name.plural id = model_hash["id"] account_cname = Array.wrap(model_hash["account_cname_tesim"]).first end + [id, base_route_name, account_cname] + end - request_params = %i[protocol host port].map { |method| ["request_#{method}".to_sym, request.send(method)] }.to_h - url = get_url(id:, request: request_params, account_cname:, base_route_name:) + # Extracts protocol, host, and port information from the request. + # + # @param request [ActionDispatch::Request] the current HTTP request object + # @return [Hash] a hash containing the protocol, host, and port extracted from the request + def extract_request_params(request) + %i[protocol host port].map { |method| ["request_#{method}".to_sym, request.send(method)] }.to_h + end - # pass search query params to work show page - params[:q].present? ? "#{url}?q=#{params[:q]}" : url + # Builds the base URL for the given model and request information. + # + # @param id [String] the model's ID + # @param request_params [Hash] the extracted request parameters (protocol, host, port) + # @param account_cname [String, nil] the account cname, if applicable + # @param base_route_name [String] the base route name (e.g., 'works', 'collections') + # @return [String] the constructed base URL + def build_url(id, request_params, account_cname, base_route_name) + get_url(id: id, request: request_params, account_cname: account_cname, base_route_name: base_route_name) end - private + # Appends the appropriate query parameters to the base URL based on the model and params. + # + # @param url [String] the base URL + # @param model [Object] the model object (e.g., work or collection) + # @param params [Hash] the query parameters, which may include search queries + # @return [String] the URL with appended query parameters, if applicable + def append_query_params(url, model, params) + return url if params[:q].blank? + if params[:q].present? && model.any_highlighting_in_all_text_fields? + "#{url}?parent_query=#{params[:q]}&highlight=true" + else + "#{url}?q=#{params[:q]}" + end + end + # Constructs a URL with the given parameters. + # + # @param id [String] the model's ID + # @param request [Hash] the request parameters (protocol, host, port) + # @param account_cname [String, nil] the account cname, if applicable + # @param base_route_name [String] the base route name (e.g., 'works', 'collections') + # @return [String] the constructed URL def get_url(id:, request:, account_cname:, base_route_name:) new_url = "#{request[:request_protocol]}#{account_cname || request[:request_host]}" new_url += ":#{request[:request_port]}" if Rails.env.development? || Rails.env.test? diff --git a/app/presenters/blacklight/thumbnail_presenter_decorator.rb b/app/presenters/blacklight/thumbnail_presenter_decorator.rb new file mode 100644 index 000000000..b9faf5f4d --- /dev/null +++ b/app/presenters/blacklight/thumbnail_presenter_decorator.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +# OVERRIDE Blacklight 7.35 to pass the query parameters to the UV via the thumbnail URL +module Blacklight + module ThumbnailPresenterDecorator + ## + # Render the thumbnail, if available, for a document and + # link it to the document record. + # + # @param [Hash] image_options to pass to the image tag + # @param [Hash] url_options to pass to #link_to_document + # @return [String] + def thumbnail_tag(image_options = {}, url_options = {}) + value = thumbnail_value(image_options) + return value if value.nil? || url_options[:suppress_link] + view_context.link_to_document document, value, url_options + end + end +end + +Blacklight::ThumbnailPresenter.prepend(Blacklight::ThumbnailPresenterDecorator) diff --git a/app/views/catalog/_index_header_list_default.html.erb b/app/views/catalog/_index_header_list_default.html.erb index 000176cd9..82f035fe9 100644 --- a/app/views/catalog/_index_header_list_default.html.erb +++ b/app/views/catalog/_index_header_list_default.html.erb @@ -1,6 +1,9 @@ <%# OVERRIDE Hyrax v5.0.1 to collection badge and markdown of links %>
-

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

+

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

+ <% 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 %> 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 %>