From 5d385e2bf9ebc3dfbe6e92a3a8cecbfbe1f03e5f Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Wed, 30 Oct 2024 16:45:42 -0400 Subject: [PATCH 1/2] Snippet fixes for catalog search into viewer Fix generated work url. Adjust char limit to accomplish full text search. Modify view to only load field_value once. Adjust specs for url change. --- app/controllers/catalog_controller.rb | 4 +++- app/helpers/shared_search_helper.rb | 3 +-- app/views/catalog/_index_list_default.html.erb | 2 +- spec/helpers/shared_search_helper_spec.rb | 9 +++++---- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index bd7c75080..652e100bf 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -82,6 +82,7 @@ def self.uploaded_field config.http_method = :post ## Default parameters to send to solr for all search-like requests. See also SolrHelper#solr_search_params + # Max fragsize is needed to not cut off full text search at default 51,000 characters config.default_solr_params = { qt: "search", rows: 10, @@ -93,7 +94,8 @@ def self.uploaded_field "hl.simple.pre": "", "hl.simple.post": "", "hl.snippets": 30, - "hl.fragsize": 100 + "hl.fragsize": 100, + "hl.maxAnalyzedChars": 5100000 } # Specify which field to use in the tag cloud on the homepage. diff --git a/app/helpers/shared_search_helper.rb b/app/helpers/shared_search_helper.rb index 4f3dc5d92..303c52289 100644 --- a/app/helpers/shared_search_helper.rb +++ b/app/helpers/shared_search_helper.rb @@ -63,11 +63,10 @@ def build_url(id, request_params, account_cname, base_route_name) # @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]}" + url end end diff --git a/app/views/catalog/_index_list_default.html.erb b/app/views/catalog/_index_list_default.html.erb index dd935e223..03359fd09 100644 --- a/app/views/catalog/_index_list_default.html.erb +++ b/app/views/catalog/_index_list_default.html.erb @@ -11,7 +11,7 @@ <% if should_render_index_field?(document, field) && field_value.present? %>
<%= render_index_field_label document, field: field_name %>
-
<%= markdown(doc_presenter.field_value field) %>
+
<%= markdown(field_value) %>
<% end %> <% end %> diff --git a/spec/helpers/shared_search_helper_spec.rb b/spec/helpers/shared_search_helper_spec.rb index 651b2d9df..17127f189 100644 --- a/spec/helpers/shared_search_helper_spec.rb +++ b/spec/helpers/shared_search_helper_spec.rb @@ -28,8 +28,9 @@ it 'returns #generate_work_url with a query' do allow(params).to receive(:[]).with(:q).and_return('foo') + allow(work_hash).to receive(:any_highlighting_in_all_text_fields?).and_return(false) - url = "#{request.protocol}#{cname}/concern/generic_works/#{uuid}?q=foo" + url = "#{request.protocol}#{cname}/concern/generic_works/#{uuid}" expect(helper.generate_work_url(work_hash, request, params)).to eq(url) end @@ -50,12 +51,12 @@ expect(helper.generate_work_url(work_hash, request)).to eq(url) end - it 'returns #generate_work_url with a query' do + it 'returns #generate_work_url if given a query but no highlighting' do allow(params).to receive(:[]).with(:q).and_return('foo') + allow(work_hash).to receive(:any_highlighting_in_all_text_fields?).and_return(false) - url = "#{request.protocol}#{account.cname}:#{request.port}/concern/generic_works/#{uuid}?q=foo" + url = "#{request.protocol}#{account.cname}:#{request.port}/concern/generic_works/#{uuid}" expect(helper.generate_work_url(work_hash, request, params)).to eq(url) - allow(work_hash).to receive(:any_highlighting_in_all_text_fields?).and_return(false) end it 'returns #generate_work_url with a query and highlight true for UV' do From 2d74b8cf359740f9cbf245c5a0d660982a3094a8 Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Wed, 30 Oct 2024 17:40:30 -0400 Subject: [PATCH 2/2] Rubocop doesn't like big numbers --- app/controllers/catalog_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 652e100bf..b6c8faf74 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -95,7 +95,7 @@ def self.uploaded_field "hl.simple.post": "", "hl.snippets": 30, "hl.fragsize": 100, - "hl.maxAnalyzedChars": 5100000 + "hl.maxAnalyzedChars": 5_100_000 } # Specify which field to use in the tag cloud on the homepage.