Browse Source

Improve searchng for `documents`, `doctrines` and `annotations`

pull/108/head
alexdbondoc17 4 years ago
parent
commit
596c5ed2d6
  1. 2
      app/components/doctrine_index_component/doctrine_index_component.html.erb
  2. 4
      app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb
  3. 2
      app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb
  4. 4
      app/controllers/concerns/annotation_search.rb
  5. 6
      app/controllers/concerns/doctrine_search.rb
  6. 5
      app/models/annotation.rb
  7. 7
      app/models/cdao/document.rb
  8. 2
      app/models/cdao/jurisprudence.rb
  9. 4
      app/models/doctrine.rb
  10. 10
      app/models/doctrine_jurisprudence.rb
  11. 2
      app/views/documents/show.html.erb

2
app/components/doctrine_index_component/doctrine_index_component.html.erb

@ -8,7 +8,7 @@
<% date_or_year = jurisprudence.docdate.present? ? jurisprudence.docdate.to_date.strftime("%B %d, %Y") : jurisprudence.year %>
<h5 class="clickable-link" style="color: darkred;" href="<%= document_path(jurisprudence, is_index_table: false, subject_ids: params[:subject_ids]) %>"> <%= [document_title, jurisprudence.reference_number, date_or_year].join(", ") %> </h5>
<% annotations.order(created_at: :desc).each do |annotation| %>
<% annotations.sort_by { |a| [a.document.library.rank, -a.document.year, -a.document.doc_date.strftime("%Y-%m-%d")] }.each do |annotation| %>
<p class="mb-2 ms-3 clickable-link" href="<%= show_url %>">
<% annotated_documents_title = [] %>
<% annotation.documents.each do |annotated_document| %>

4
app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb

@ -21,11 +21,11 @@
<% if opts[:is_doctrines_index].present? %>
<% document_title = jurisprudence.short_title || jurisprudence.title %>
<% date_or_year = jurisprudence.docdate.present? ? jurisprudence.docdate.to_date.strftime("%B %d, %Y") : jurisprudence.year %>
<% date_or_year = jurisprudence.docdate.present? ? jurisprudence.docdate.to_date.strftime('%B %d, %Y') : jurisprudence.year %>
<h5 style="color: darkred;"> <%= [document_title, jurisprudence.reference_number, date_or_year].join(", ") %> </h5>
<% end %>
<% annotations.order(created_at: :desc).each do |annotation| %>
<% annotations.sort_by { |a| [a.document.library.rank, -a.document.year, -a.document.doc_date.strftime('%Y-%m-%d')] }.each do |annotation| %>
<p class="mb-2 ms-3">
<% annotated_documents_title = [] %>
<% annotation.documents.each do |annotated_document| %>

2
app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb

@ -88,7 +88,7 @@
<div class="row-flex">
<div class="annot-header"> <h5> Annotations </h5> </div>
<div class="" id="annotationsIndexView">
<% doctrine.annotations.order(created_at: :desc).each do |annotation| %>
<% annotations.sort_by { |a| [a.document.library.rank, -a.document.year, -a.document.doc_date.strftime("%Y-%m-%d")] }.each do |annotation| %>
<% document_title = annotation.document.short_title || annotation.document.title %>
<% date_or_year = annotation.document.docdate.present? ? annotation.document.docdate.strftime("%B %d, %Y") : annotation.document.year %>
<% annotated_documents_title = [] %>

4
app/controllers/concerns/annotation_search.rb

@ -9,7 +9,9 @@ module AnnotationSearch
with field, search_params[field] if search_params[field].present?
end
order_by :created_at, :desc
order_by :library_rank, :asc
order_by :search_year, :desc
order_by :search_doc_date, :desc
paginate page: search_params[:page] || 1, per_page: search_params[:per_page] || 20
end

6
app/controllers/concerns/doctrine_search.rb

@ -23,6 +23,12 @@ module DoctrineSearch
without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present?
if search_params[:sort_by].blank?
order_by :search_year, :desc
order_by :search_doc_date, :desc
order_by :reference_number, :desc
end
paginate page: search_params[:page] || 1, per_page: search_params[:per_page] || 20
end

5
app/models/annotation.rb

@ -4,6 +4,7 @@ class Annotation < ApplicationRecord
belongs_to :doctrine, optional: false
belongs_to :document, polymorphic: true, optional: false
has_one :library, through: :document
has_many :annotation_documents, inverse_of: :annotation, dependent: :destroy
accepts_nested_attributes_for :annotation_documents, allow_destroy: true
@ -33,6 +34,10 @@ class Annotation < ApplicationRecord
integer :document_id
integer :doctrine_id
join(:library_rank, target: Cdao::Document, type: :integer, join: { from: :id, to: :document_id })
join(:search_year, target: Cdao::Document, type: :integer, join: { from: :id, to: :document_id })
join(:search_doc_date, target: Cdao::Document, type: :date, join: { from: :id, to: :document_id })
date :created_at
date :updated_at

7
app/models/cdao/document.rb

@ -1,6 +1,8 @@
class Cdao::Document < Cdao::Base
self.table_name = "documents"
belongs_to :library, class_name: "Cdao::Library", optional: false
alias_attribute :docdate, :doc_date
alias_attribute :short_title, :title
@ -69,6 +71,11 @@ class Cdao::Document < Cdao::Base
integer :id
integer :year
integer :library_rank do
library.rank
end
integer :search_year do
year.present? && year > 0 ? year : (doc_date.try :year)
end

2
app/models/cdao/jurisprudence.rb

@ -163,7 +163,5 @@ class Cdao::Jurisprudence < Cdao::Base
boolean :is_only_in_premium_libraries do
is_only_in_premium_libraries?
end
join(:phil_rep, :target => Annotation, :type => :string, :join => { :from => :document_id, :to => :id })
end
end

4
app/models/doctrine.rb

@ -101,7 +101,9 @@ class Doctrine < ApplicationRecord
paper_trail.originator.to_i
end
join(:phil_rep, :target => Annotation, :type => :string, :join => { :from => :annotation_doctrine_id, :to => :id })
join(:search_doc_date, :target => DoctrineJurisprudence, :type => :date, :join => { :from => :doctrine_id, :to => :id })
join(:search_year, :target => DoctrineJurisprudence, :type => :integer, :join => { :from => :doctrine_id, :to => :id })
join(:reference_number, :target => DoctrineJurisprudence, :type => :string, :join => { :from => :doctrine_id, :to => :id })
date :created_at
end

10
app/models/doctrine_jurisprudence.rb

@ -3,4 +3,14 @@ class DoctrineJurisprudence < ApplicationRecord
belongs_to :doctrine, optional: false
belongs_to :jurisprudence, class_name: "Cdao::Jurisprudence", optional: false
searchable do
integer :doctrine_id
integer :jurisprudence_id
join(:search_doc_date, :target => Cdao::Jurisprudence, :type => :date, :join => { :from => :id, :to => :jurisprudence_id })
join(:search_year, :target => Cdao::Jurisprudence, :type => :integer, :join => { :from => :id, :to => :jurisprudence_id })
join(:reference_number, :target => Cdao::Jurisprudence, :type => :string, :join => { :from => :id, :to => :jurisprudence_id })
join(:subject_ids, :target => Doctrine, :type => :integer, :multiple => true, :join => { :from => :id, :to => :doctrine_id })
end
end

2
app/views/documents/show.html.erb

@ -96,7 +96,7 @@
</thead>
<tbody>
<%= render(CitationIndexTableComponent.with_collection(@cited_in_documents, current_user: current_user)) %>
<%= render(CitationIndexTableComponent.with_collection(@cited_in_documents.sort_by { |cited| -cited.doc_date }, current_user: current_user)) %>
</tbody>
</table>
</div>

Loading…
Cancel
Save