diff --git a/app/components/doctrine_index_component/doctrine_index_component.html.erb b/app/components/doctrine_index_component/doctrine_index_component.html.erb
index 0c6d2a4..5db9e35 100644
--- a/app/components/doctrine_index_component/doctrine_index_component.html.erb
+++ b/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 %>
<% annotated_documents_title = [] %>
<% annotation.documents.each do |annotated_document| %>
diff --git a/app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb b/app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb
index 0d559d0..164486a 100644
--- a/app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb
+++ b/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 %>
<% annotated_documents_title = [] %>
<% annotation.documents.each do |annotated_document| %>
diff --git a/app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb b/app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb
index 91c2fa5..9aaa1e6 100644
--- a/app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb
+++ b/app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb
@@ -88,7 +88,7 @@
- <% 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 = [] %>
diff --git a/app/controllers/concerns/annotation_search.rb b/app/controllers/concerns/annotation_search.rb
index 8545c9f..2aea88f 100644
--- a/app/controllers/concerns/annotation_search.rb
+++ b/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
diff --git a/app/controllers/concerns/doctrine_search.rb b/app/controllers/concerns/doctrine_search.rb
index efa4e22..8205d54 100644
--- a/app/controllers/concerns/doctrine_search.rb
+++ b/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
diff --git a/app/models/annotation.rb b/app/models/annotation.rb
index c8071e8..d66c4a1 100644
--- a/app/models/annotation.rb
+++ b/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
@@ -32,6 +33,10 @@ class Annotation < ApplicationRecord
searchable do
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
diff --git a/app/models/cdao/document.rb b/app/models/cdao/document.rb
index 3d9deb6..29bcd6c 100644
--- a/app/models/cdao/document.rb
+++ b/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
diff --git a/app/models/cdao/jurisprudence.rb b/app/models/cdao/jurisprudence.rb
index 1ebaa2f..78c935d 100644
--- a/app/models/cdao/jurisprudence.rb
+++ b/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
diff --git a/app/models/doctrine.rb b/app/models/doctrine.rb
index 7ba199a..d9d5e1c 100644
--- a/app/models/doctrine.rb
+++ b/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
diff --git a/app/models/doctrine_jurisprudence.rb b/app/models/doctrine_jurisprudence.rb
index d2749b6..cbc9d73 100644
--- a/app/models/doctrine_jurisprudence.rb
+++ b/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
diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb
index 3a6792f..d4b934a 100644
--- a/app/views/documents/show.html.erb
+++ b/app/views/documents/show.html.erb
@@ -96,7 +96,7 @@
- <%= 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)) %>