Skip to content

Commit

Permalink
Merge pull request #2042 from sul-dlss/no-mods-parsing
Browse files Browse the repository at this point in the history
move away from mods parsing in search results
  • Loading branch information
cbeer committed Nov 13, 2018
2 parents 863c26b + 7bc90a6 commit d8d5258
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 10 deletions.
3 changes: 2 additions & 1 deletion app/helpers/record_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def link_to_mods_name(name)
link_to(name, search_catalog_path(q: "\"#{name}\"", search_field: 'search_author'))
end

# We need this to remove the ending ":" from the role labels
# We need this to remove the ending ":" from the role labels only in data from
# mods_display
def sanitize_mods_name_label(label)
label.sub(/:$/, '')
end
Expand Down
14 changes: 14 additions & 0 deletions app/models/concerns/mods_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,18 @@ def prettified_mods
return nil unless self["modsxml"]
@prettified_mods ||= CodeRay::Duo[:xml, :div].highlight(self["modsxml"]).html_safe
end

##
# Convenience accessors and parsers for mods_display content already indexed

##
# A ModsDisplay::Values object dumped while indexing. The object is needed
# as there is there is some necessary display logic.
def mods_display_name
fetch(:author_struct, [])
end

def mods_abstract
fetch(:summary_display, [])
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
<% if document[:vern_title_display].present? %>
<li><%= document[:vern_title_display].html_safe %></li>
<% end %>
<% if document.mods.name.present? && document.mods.name.first.values.present? %>
<% if document.mods_display_name.present? %>
<li>
<% name = document.mods_display_name.first %>
<%= link_to_mods_name(name['link']) %> <%= name['post_text'] %>
</li>
<%# TODO: Remove this elsif block after new mods index is in place %>
<% elsif document.mods.name.present? && document.mods.name.first.values.present? %>
<li>
<% name = document.mods.name.first %>
<%= link_to_mods_name(name.values.first) %> (<%= sanitize_mods_name_label(name.label) %>)
Expand Down
11 changes: 7 additions & 4 deletions app/views/catalog/_summary_data.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@
<% end %>
<% end %>
<% elsif document.respond_to?(:mods) && document.mods.present? %>
<% if document.mods.abstract.present? %>
<%= document.mods.abstract.map(&:values).join('<br/>').html_safe %>
<% end %>
<% elsif document.mods_abstract.present? %>
<%= document.mods_abstract.join('<br/>').html_safe %>
<% elsif document[:summary_display].present? %>
<div>
<%= document[:summary_display].join('<br/>').html_safe %>
</div>
<%# TODO: Remove this elsif block after new mods index is in place %>
<% elsif document.respond_to?(:mods) && document.mods.present? %>
<% if document.mods.abstract.present? %>
<%= document.mods.abstract.map(&:values).join('<br/>').html_safe %>
<% end %>
<% end %>
1 change: 1 addition & 0 deletions config/solr_configs/solrconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@
author_meeting_display, vern_author_meeting_display,
author_person_display, vern_author_person_display,
author_person_full_display, vern_author_person_full_display,
author_struct:[json],
bookplates_display,
collection,
collection_type,
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/solr_documents/31.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
:pub_date: 2010
:beginning_year_isi: 2010
:imprint_display: 2010
:summary_display:
- Nunc venenatis et odio ac elementum. Nulla ornare faucibus laoreet
5 changes: 5 additions & 0 deletions spec/fixtures/solr_documents/47.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
:format_main_ssim: "Archive/Manuscript"
:modsxml: <%= mods_everything %>
:collection_type: Digital Collection
:author_struct:
- '{"link":"J. Smith","search":"\"J. Smith\"","post_text":"(Author)"}'
- '{"link":"B. Smith","search":"\"B. Smith\"","post_text":"(Producer)"}'
:summary_display:
- This collection of Virtual Objects is really important.
6 changes: 5 additions & 1 deletion spec/views/catalog/_index_mods.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
collection_with_title: ['12345 -|- Collection Title'],
modsxml: mods_everything,
physical: ["The Physical Extent"],
imprint_display: ["Imprint Statement"]
imprint_display: ["Imprint Statement"],
author_struct: [
{ 'link' => 'J. Smith', 'search' => '"J. Smith"', 'post_text' => '(Author)' },
{ 'link' => 'B. Smith', 'search' => '"B. Smith"', 'post_text' => '(Producer)' },
]
)
)
expect(view).to receive(:show_presenter).and_return(presenter)
Expand Down
6 changes: 5 additions & 1 deletion spec/views/catalog/_index_mods_collection.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
SolrDocument.new(
id: 'abc123',
modsxml: mods_everything,
physical: ["The Physical Extent"]
physical: ["The Physical Extent"],
author_struct: [
{ 'link' => 'J. Smith', 'search' => '"J. Smith"', 'post_text' => '(Author)' },
{ 'link' => 'B. Smith', 'search' => '"B. Smith"', 'post_text' => '(Producer)' },
]
)
)
render
Expand Down
7 changes: 6 additions & 1 deletion spec/views/preview/_show_mods.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
display_type: ["image"],
item_display: [ "123 -|- GREEN -|- STACKS -|- -|- -|- -|- -|- -|- ABC 123" ],
isbn_display: [ 123 ],
imprint_display: ["Imprint Statement"]
imprint_display: ["Imprint Statement"],
author_struct: [
{ 'link' => 'J. Smith', 'search' => '"J. Smith"', 'post_text' => '(Author)' },
{ 'link' => 'B. Smith', 'search' => '"B. Smith"', 'post_text' => '(Producer)' },
],
summary_display: ['Nunc venenatis et odio ac elementum. Nulla ornare faucibus laoreet']
) }

before do
Expand Down

0 comments on commit d8d5258

Please sign in to comment.