From 74a094aae83250b6f64bb788602a123075e3579c Mon Sep 17 00:00:00 2001 From: alexdbondoc17 Date: Tue, 15 Mar 2022 00:38:05 +0000 Subject: [PATCH 1/5] Add `callback` for `annotation` --- app/models/annotation.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/models/annotation.rb b/app/models/annotation.rb index acf06cb..d067d9d 100644 --- a/app/models/annotation.rb +++ b/app/models/annotation.rb @@ -13,6 +13,8 @@ class Annotation < ApplicationRecord validates :content, presence: true + before_save :parse_content + def documents annotation_documents.collect(&:document) end @@ -30,6 +32,18 @@ class Annotation < ApplicationRecord def citing_document_ids documents.map(&:id) end + + + def parse_content + pr = phil_rep.gsub(/(PhilRep|Phil)\.?,?/i, "Phil") + pr = pr.gsub(/(PhilRep|Phil)\.?,?/i, "Phil") + annotated_doc_title = document.short_title || document.title + annotated_doc_date = document.doc_date.present? ? document.doc_date.try(:strftime, "%B %d, %Y") : document.year + contents = content.split(" citing ") + contents[0] = [annotated_doc_title, document.clean_reference_number, annotated_doc_date, pr].join(", ") + + self.content = contents.join(" citing ") + end searchable do integer :document_id From a446aa3bd523ce800eb3e326b8fad52d341e917c Mon Sep 17 00:00:00 2001 From: alexdbondoc17 Date: Tue, 15 Mar 2022 00:40:08 +0000 Subject: [PATCH 2/5] Removee `searchable` in `doctrine_jurisprudence` --- app/models/doctrine_jurisprudence.rb | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/app/models/doctrine_jurisprudence.rb b/app/models/doctrine_jurisprudence.rb index cbc9d73..6332e90 100644 --- a/app/models/doctrine_jurisprudence.rb +++ b/app/models/doctrine_jurisprudence.rb @@ -3,14 +3,5 @@ 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 From d92783bdfa7410063042a2e154517c93967fb666 Mon Sep 17 00:00:00 2001 From: alexdbondoc17 Date: Tue, 15 Mar 2022 00:40:39 +0000 Subject: [PATCH 3/5] Improve searchable in `doctrine` --- app/models/doctrine.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/models/doctrine.rb b/app/models/doctrine.rb index a2470a7..ec1cb19 100644 --- a/app/models/doctrine.rb +++ b/app/models/doctrine.rb @@ -183,10 +183,8 @@ class Doctrine < ApplicationRecord paper_trail.originator.to_i end - 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 + + string :headnote end end From 185030b45d07d8a4dc5d3e7dc20cab33a630c095 Mon Sep 17 00:00:00 2001 From: alexdbondoc17 Date: Tue, 15 Mar 2022 00:54:24 +0000 Subject: [PATCH 4/5] 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 @@

@@ -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 = [] %> From 353e53bb43c20f5311824575e37602dd418226af Mon Sep 17 00:00:00 2001 From: alexdbondoc17 Date: Tue, 15 Mar 2022 01:26:44 +0000 Subject: [PATCH 5/5] Fix `doctrine_search` --- app/controllers/concerns/doctrine_search.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/concerns/doctrine_search.rb b/app/controllers/concerns/doctrine_search.rb index 8205d54..92c245f 100644 --- a/app/controllers/concerns/doctrine_search.rb +++ b/app/controllers/concerns/doctrine_search.rb @@ -23,10 +23,8 @@ 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 + if search_params[:is_group_by_headnote].to_s.eql?("true") + group :headnote end paginate page: search_params[:page] || 1, per_page: search_params[:per_page] || 20