Skip to content

Commit

Permalink
Snippet fixes for catalog search into viewer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
laritakr committed Oct 30, 2024
1 parent 6b9b19f commit 5d385e2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
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": 5100000
}

# 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

0 comments on commit 5d385e2

Please sign in to comment.