Skip to content
Permalink
Browse files

Adding search by tag (and title)

  • Loading branch information...
arfon committed Aug 16, 2019
1 parent fcac2bc commit 413b30e95c9eb3e508ba2e0cdedc361db1d08820
Showing with 22 additions and 6 deletions.
  1. +7 −0 app/controllers/papers_controller.rb
  2. +8 −6 app/models/paper.rb
  3. +6 −0 app/views/papers/show.html.erb
  4. +1 −0 config/routes.rb
@@ -89,6 +89,13 @@ def filter
)
@term = "by #{params['author']}"

elsif params['tag']
@papers = Paper.search(params['tag'], fields: [:tags, :title], order: { accepted_at: :desc },
:page => params[:page],
:per_page => 10
)
@term = "#{params['tag']}"

elsif params['issue']
@papers = Paper.search(params['issue'], fields: [{issue: :exact}], order: { page: :desc },
:page => params[:page],
@@ -106,14 +106,15 @@ def should_index?

def search_data
{
accepted_at: accepted_at,
authors: scholar_authors,
issue: issue,
languages: language_tags,
page: page,
tags: author_tags,
authors: scholar_authors,
accepted_at: accepted_at,
year: year,
title: scholar_title,
volume: volume,
issue: issue,
page: page
year: year
}
end

@@ -127,6 +128,7 @@ def self.popular
end

def scholar_title
return nil unless accepted?
metadata['paper']['title']
end

@@ -143,7 +145,7 @@ def language_tags
def author_tags
return [] unless accepted?
if metadata['paper']['tags']
return metadata['paper']['tags']
return metadata['paper']['tags'] - language_tags
else
return []
end
@@ -141,6 +141,12 @@
<div class="label">Citation</div>
<p><%= @paper.citation_string %><br ><a href="#" id="joss-paper-bibtex" class="clippy" data-clipboard-action="copy" data-clipboard-text="BibTex entry not available. Please check back later.">Copy BibTeX entry &raquo;</a></p>

<div class="label">Tags</div>
<p>
<% @paper.author_tags.each do |tag| %>
<span class="badge-lang"><%= link_to tag, papers_by_tag_path(:tag => tag) %></span>
<% end %>
</p>
<div class="label">Altmetrics</div>
<div style='padding-bottom: 10px;' data-badge-type='donut' class='altmetric-embed' data-badge-popover='right' data-hide-no-mentions='false' data-doi="<%= @paper.doi %>"></div>

@@ -20,6 +20,7 @@
get '/papers/lookup/:id', :to => "papers#lookup"
get '/papers/in/:language', to: "papers#filter", as: 'papers_by_language'
get '/papers/by/:author', to: "papers#filter", as: 'papers_by_author'
get '/papers/tagged/:tag', to: "papers#filter", as: 'papers_by_tag'
get '/papers/issue/:issue', to: "papers#filter", as: 'papers_by_issue'
get '/papers/volume/:volume', to: "papers#filter", as: 'papers_by_volume'
get '/papers/year/:year', to: "papers#filter", as: 'papers_by_year'

0 comments on commit 413b30e

Please sign in to comment.
You can’t perform that action at this time.