From 185030b45d07d8a4dc5d3e7dc20cab33a630c095 Mon Sep 17 00:00:00 2001 From: alexdbondoc17 Date: Tue, 15 Mar 2022 00:54:24 +0000 Subject: [PATCH] Use SOLR for `annotations` --- app/components/doctrine_index_component.rb | 11 +++++++++-- .../doctrine_index_component.html.erb | 4 ++-- app/components/document_doctrine_index_component.rb | 8 +++++++- .../document_doctrine_index_component.html.erb | 2 +- .../document_doctrine_show_component.html.erb | 4 ++-- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/components/doctrine_index_component.rb b/app/components/doctrine_index_component.rb index b8b9908..50440b7 100644 --- a/app/components/doctrine_index_component.rb +++ b/app/components/doctrine_index_component.rb @@ -2,6 +2,8 @@ class DoctrineIndexComponent < BaseComponent with_collection_parameter :doctrine attr_reader :doctrine, :opts + include AnnotationSearch + def initialize(doctrine:, current_user:, opts: {}) @doctrine = doctrine @opts = opts @@ -10,10 +12,10 @@ class DoctrineIndexComponent < BaseComponent delegate :id, to: :doctrine delegate :subject_ids, to: :doctrine delegate :content, to: :doctrine - delegate :annotations, to: :doctrine delegate :subjects, to: :doctrine delegate :headnote, to: :doctrine delegate :doctrine_jurisprudences, to: :doctrine + delegate :jurisprudences, to: :doctrine def annotation_form_url doctrine_annotations_path(doctrine_id: id) @@ -26,7 +28,7 @@ class DoctrineIndexComponent < BaseComponent def jurisprudence return nil if doctrine_jurisprudences.blank? - doctrine_jurisprudences.first.jurisprudence + jurisprudences.first end def document_title(annotation) @@ -53,6 +55,11 @@ class DoctrineIndexComponent < BaseComponent annotation.phil_rep.gsub(/(PhilRep|Phil)\.?,?/i, "Phil") end + def annotations + search = annotation_search(doctrine_id: id) + search.results + end + def render? doctrine.present? && doctrine.persisted? end 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 fcf0e04..db593ad 100644 --- a/app/components/doctrine_index_component/doctrine_index_component.html.erb +++ b/app/components/doctrine_index_component/doctrine_index_component.html.erb @@ -8,13 +8,13 @@ <% date_or_year = jurisprudence.docdate.present? ? jurisprudence.docdate.to_date.strftime("%B %d, %Y") : jurisprudence.year %> - <% annotations.sort_by { |a| [a.document.library.rank, -a.document.year, -a.document.doc_date.strftime("%Y-%m-%d")] }.each do |annotation| %> + <% annotations.each do |annotation| %>
<%= [document_title, jurisprudence.reference_number, date_or_year].join(", ") %>
<% end %> - <% annotations.sort_by { |a| [a.document.library.rank, -a.document.year, -a.document.doc_date.strftime('%Y-%m-%d')] }.each do |annotation| %> + <% annotations.each do |annotation| %>

<% 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 3680319..f3b954f 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 @@ -6,7 +6,7 @@

- Edit + Edit Delete
@@ -85,7 +85,7 @@
Annotations
- <% doctrine.annotations.sort_by { |a| [a.document.library.rank, -a.document.year, -a.document.doc_date.strftime("%Y-%m-%d")] }.each do |annotation| %> + <% annotations.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 = [] %>