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

ANW-363 Add search terms in context #3080

Closed
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
6 changes: 2 additions & 4 deletions backend/app/model/solr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def initialize(query_string, opts = {})
@pagination = nil
@solr_params = []
@facet_fields = []
@highlighting = false
highlighting(true)

@show_suppressed = false
@show_published_only = false
Expand Down Expand Up @@ -326,9 +326,7 @@ def to_solr_url

if @highlighting
add_solr_param(:hl, "true")
if @query_type == :standard
add_solr_param(:"hl.fl", "*")
end
add_solr_param(:"hl.fl", "*")
end

unless @show_suppressed
Expand Down
14 changes: 14 additions & 0 deletions public/app/helpers/view_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,18 @@ def archival_object_base_url(result)

return url
end

def referrer_search_terms(ref)
(URI(ref).query).nil? ? nil : CGI::parse(URI(ref).query)["q[]"]
end

def highlights(keyword, text)
if text.include?(keyword.capitalize)
text.gsub!(/#{keyword.capitalize}/, "<span class=\"searchterm\">#{keyword.capitalize}<\/span>")
elsif text.include?(keyword)
text.gsub!(/#{keyword}/, "<span class=\"searchterm\">#{keyword}<\/span>")
end

return text
end
end
3 changes: 2 additions & 1 deletion public/app/models/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Record
:identifier, :classifications, :level, :other_level, :linked_digital_objects,
:container_titles_and_uris

attr_accessor :criteria
attr_accessor :criteria, :highlights

ABSTRACT = %w(abstract scopecontent)

Expand Down Expand Up @@ -51,6 +51,7 @@ def initialize(solr_result, full = false)
@classifications = parse_classifications
@agents = parse_agents(subjects)
@extents = parse_extents
@highlights = raw['highlighting']
end

def [](k)
Expand Down
4 changes: 3 additions & 1 deletion public/app/models/solr_results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def parse_records(full)
def parse_record(result, full)
record = record_for_type(result, full)
record.criteria = @search_opts

unless @raw['highlighting'][result['id']].nil?
record.highlights = @raw['highlighting'][result['id']]
end
record
end
end
4 changes: 3 additions & 1 deletion public/app/services/archives_space_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class ArchivesSpaceClient

DEFAULT_SEARCH_OPTS = {
'publish' => true,
'page_size' => AppConfig[:pui_search_results_page_size] }
'page_size' => AppConfig[:pui_search_results_page_size],
'hl' => true
}

def self.init
@instance = self.new
Expand Down
21 changes: 19 additions & 2 deletions public/app/views/shared/_idbadge.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<% ref = request.env['HTTP_REFERER'].empty? ? request.referrer : request.env['HTTP_REFERER'] %>
<% ref_search_terms = ((@search.nil? || @search[:q].empty?) && !ref.nil?) ? referrer_search_terms(ref) : nil %>
<%
if result.level
if result.primary_type =~ /digital_object/
Expand All @@ -12,6 +14,7 @@ else
end
%>


<%# build URL with slugs depending on the primary type %>
<% case result.primary_type %>
<% when "resource" %>
Expand Down Expand Up @@ -41,8 +44,22 @@ end
<%= (props.fetch(:full,false)? '<h1>' : '<h3>').html_safe %>
<% if !props.fetch(:full,false) %>
<a class="record-title" href="<%= app_prefix(url) %>">
<%== props.fetch(:infinite_item, false) ? result.parse_full_title(true) : result.display_string %>
</a>
<% if !ref_search_terms.nil? %>
<% ref_search_terms.each do |k| %>
<% highlights(k, result["title"]) %>
<% end %>
<%= result["title"].html_safe %>
<% elsif !@search[:q].empty? %>
<% @search[:q].each do |q| %>
<% q.split(' ').each do |k| %>
<% highlights(k, result["title"]) %>
<% end %>
<% end %>
<%= result["title"].html_safe %>
<% else %>
<%== props.fetch(:infinite_item, false) ? result.parse_full_title(true) : result.display_string %>
<% end %>
</a>
<% else %>
<%== result.display_string %>
<% end %>
Expand Down
41 changes: 40 additions & 1 deletion public/app/views/shared/_result_record_summary.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<% ref = request.env['HTTP_REFERER'].empty? ? request.referrer : request.env['HTTP_REFERER'] %>
<% ref_search_terms = ((@search.nil? || @search[:q].empty?) && !ref.nil?) ? referrer_search_terms(ref) : nil %>
<div class="recordsummary" style="clear:both">
<% if !result['parent_institution_name'].blank? %>
<div>
Expand All @@ -13,6 +15,20 @@
end
if !note_struct['note_text'].blank?
%>
<% unless @search[:q][0] == '*' %>
<% if ref_search_terms.nil? %>
<% @search[:q].each do |q| %>
<% q.split(' ').each do |k| %>
<% highlights(k, note_struct['note_text']) %>
<% end %>
<% end %>
<% else %>
<% ref_search_terms.each do |k| %>
<% highlights(k, note_struct['note_text']) %>
<% end %>
<% end %>
<% end %>

<div class="abstract single_note">
<span class='inline-label'><%= note_struct['label'] %></span>
<% unless note_struct['is_inherited'].blank? %>
Expand All @@ -21,7 +37,7 @@
<% if note_struct['note_text'].length > AppConfig[:abstract_note_length] %>
<% truncated_note = note_struct['note_text'][0..AppConfig[:abstract_note_length]-1] %>
<% end_index = truncated_note.rindex(' ') || AppConfig[:abstract_note_length]-1 %>
<%= (strip_tags(truncated_note[0..end_index - 1]) + '...').html_safe %>
<%= (truncated_note[0..end_index - 1]+ ' ...').html_safe %>
<% else %>
<%= note_struct['note_text'].html_safe %>
<% end %>
Expand Down Expand Up @@ -52,6 +68,28 @@
</div>
<% end %>

<% unless result.highlights.empty? %>
<div class="highlights">
<% unless result.highlights.reject{ |k,v| k.include?('title') || k =~ (/^notes$/) || k.include?('types') || v.join(' ').split("\/").count > 2 }.count == 0 %>
<br/>
<span class='inline-label'>Search Terms in Context</span>
<br/>
<% end %>
<% result.highlights.each do |k,v| %>
<% unless k.include?('title') || k =~ (/^notes$/) || k.include?('types') || v.join(' ').split("\/").count > 2 %>
<span class='inline-label'><%= t("#{k.split('_')[0]}:") %></span>
<% if result[k].length > v.join(" ").length %>
<% v << ' ...' %>
<% end %>
<% v.each do |e| %>
<%== e.gsub(/<em>/, '<span class="searchterm">').gsub(/<\/em>/, '</span>') %>
<% end %>
<br/>
<% end %>
<% end %>
</div>
<% end %>

<div class="staff-hidden hide">
<% if result['json']['restricted'] %>
<p><h4 class='restricted'><%= I18n.t('top_container.restricted') %></h4></p>
Expand All @@ -78,4 +116,5 @@
<div class="classification-subgroups-tree largetree-container" style="display: none;"></div>
</div>
<% end %>

</div>
24 changes: 24 additions & 0 deletions public/app/views/shared/_single_note.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<% ref = request.env['HTTP_REFERER'].empty? ? request.referrer : request.env['HTTP_REFERER'] %>
<% ref_search_terms = ((@search.nil? || @search[:q].empty?) && !ref.nil?) ? referrer_search_terms(ref) : nil %>
<%
heading_size = 'h2' if heading_size.blank?
sub_heading_size = 'h3' if sub_heading_size.blank?
Expand All @@ -10,6 +12,17 @@
<% end %>
<% if note_struct.has_key?('subnotes') %>
<% note_struct['subnotes'].each do |subnote| %>
<% if !ref_search_terms.nil? %>
<% ref_search_terms.each do |k| %>
<% highlights(k, subnote['_text']) %>
<% end %>
<% elsif !@search.nil? && !@search[:q].empty? %>
<% @search[:q].each do |q| %>
<% q.split(' ').each do |k| %>
<% highlights(k, subnote['_text']) %>
<% end %>
<% end %>
<% end %>
<div class="subnote <%= 'well' if subnote['jsonmodel_type'] == 'note_citation' %>">
<% if subnote['jsonmodel_type'] == 'note_citation' %>
<<%= sub_heading_size %>><%= t('actions.cite') %></<%= sub_heading_size %>>
Expand All @@ -27,6 +40,17 @@
</div>
<% end %>
<% else %>
<% if !ref_search_terms.nil? %>
<% ref_search_terms.each do |k| %>
<% highlights(k, note_struct['note_text']) %>
<% end %>
<% elsif !@search.nil? && !@search[:q].empty? %>
<% @search[:q].each do |q| %>
<% q.split(' ').each do |k| %>
<% highlights(k, note_struct['note_text']) %>
<% end %>
<% end %>
<% end %>
<div class="note-content">
<% unless note_struct['is_inherited'].blank? %>
<%= inheritance(note_struct['is_inherited']).html_safe %>
Expand Down
38 changes: 19 additions & 19 deletions public/app/views/subjects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@
<%# FOUND IN SECTION %>
<%= render partial: 'shared/results', locals: {:results => @results, :pager => @pager} %>
</div>
<div id="sidebar" class="col-sm-3 sidebar sidebar-container">
<h3><%= t('more_about') %> '<%= @result.display_string %>'</h3>
<div class="acc_holder clear" >
<div class="panel-group" id="res_accordion">
<% if !(terms = ASUtils.wrap(@result['json']['terms'])).empty? %>
<% x = render partial: 'subjects/terms', locals: {:terms => terms, :list_clss => 'terms'} %>
<%= render partial: 'shared/accordion_panel', locals: {:p_title => t('subject_term_type'), :p_id => 'subject_terms', :p_body => x} %>
<% end %>
<% unless @result.external_documents.blank? %>
<% x = render partial: 'shared/present_list_external_docs', locals: {:list => @result.external_documents, :list_clss => 'external_docs'} %>
<%= render partial: 'shared/accordion_panel', locals: {:p_title => t('external_docs'), :p_id => 'ext_doc_list', :p_body => x} %>
<% end %>
</div>
</div>
<div id="sidebar" class="col-sm-3 sidebar sidebar-container">
<h3><%= t('more_about') %> '<%= @result.display_string %>'</h3>
<div class="acc_holder clear" >
<div class="panel-group" id="res_accordion">
<% if !(terms = ASUtils.wrap(@result['json']['terms'])).empty? %>
<% x = render partial: 'subjects/terms', locals: {:terms => terms, :list_clss => 'terms'} %>
<%= render partial: 'shared/accordion_panel', locals: {:p_title => t('subject_term_type'), :p_id => 'subject_terms', :p_body => x} %>
<% end %>
<% unless @result.external_documents.blank? %>
<% x = render partial: 'shared/present_list_external_docs', locals: {:list => @result.external_documents, :list_clss => 'external_docs'} %>
<%= render partial: 'shared/accordion_panel', locals: {:p_title => t('external_docs'), :p_id => 'ext_doc_list', :p_body => x} %>
<% end %>
</div>
<script type="text/javascript" >
initialize_accordion(".note_panel", "<%= t('accordion.expand') %>" , "<%= t('accordion.collapse') %>", <%= AppConfig[:pui_expand_all] %>);
</script>
<% unless @results.blank? || @results['total_hits'] == 0 %>
<%= render partial: 'shared/facets' %>
<% end %>
</div>
<script type="text/javascript" >
initialize_accordion(".note_panel", "<%= t('accordion.expand') %>" , "<%= t('accordion.collapse') %>", <%= AppConfig[:pui_expand_all] %>);
</script>
<% unless @results.blank? || @results['total_hits'] == 0 %>
<%= render partial: 'shared/facets' %>
<% end %>
</div>
</div>