Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snippet fixes for catalog search into viewer #2373

Merged
merged 2 commits into from
Oct 30, 2024
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
4 changes: 3 additions & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -93,7 +94,8 @@ def self.uploaded_field
"hl.simple.pre": "<span class='highlight'>",
"hl.simple.post": "</span>",
"hl.snippets": 30,
"hl.fragsize": 100
"hl.fragsize": 100,
"hl.maxAnalyzedChars": 5_100_000
}

# Specify which field to use in the tag cloud on the homepage.
Expand Down
3 changes: 1 addition & 2 deletions app/helpers/shared_search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_index_list_default.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<% if should_render_index_field?(document, field) && field_value.present? %>
<div class="row">
<dt class="col-5 text-right" data-solr-field-name="<%= field_name %>"><%= render_index_field_label document, field: field_name %></dt>
<dd class="col-7"><%= markdown(doc_presenter.field_value field) %></dd>
<dd class="col-7"><%= markdown(field_value) %></dd>
</div>
<% end %>
<% end %>
Expand Down
9 changes: 5 additions & 4 deletions spec/helpers/shared_search_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Loading