Browse Source

Use SOLR for `annotations`

pull/122/head
alexdbondoc17 4 years ago
parent
commit
185030b45d
  1. 11
      app/components/doctrine_index_component.rb
  2. 4
      app/components/doctrine_index_component/doctrine_index_component.html.erb
  3. 8
      app/components/document_doctrine_index_component.rb
  4. 2
      app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb
  5. 4
      app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb

11
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

4
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 %>
<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.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| %>
<p class="mb-2 ms-3 clickable-link" href="<%= show_url %>">
<% annotated_documents_title = [] %>
<% annotation.documents.each do |annotated_document| %>
<% ad_title = annotated_document.short_title || annotated_document.title %>
<% ad_date_or_year = annotated_document.docdate.present? ? annotated_document.docdate.strftime("%B %d, %Y") : annotated_document.year %>
<% annotated_documents_title << [" citing #{ad_title}", annotated_document.reference_number, ad_date_or_year].join(", ") %>
<% annotated_documents_title << [" citing #{ad_title}", annotated_document.clean_reference_number, ad_date_or_year].join(", ") %>
<% end %>
<strong> <%= "#{annotation.annomarks.map { |annomark| "(#{annomark.code})" }.join(" ")}" %> </strong>

8
app/components/document_doctrine_index_component.rb

@ -2,6 +2,8 @@ class DocumentDoctrineIndexComponent < BaseComponent
with_collection_parameter :doctrine
attr_reader :doctrine, :opts
include AnnotationSearch
def initialize(doctrine:, current_user:, opts: {})
@doctrine = doctrine
@opts = opts
@ -10,7 +12,6 @@ class DocumentDoctrineIndexComponent < 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
@ -47,6 +48,11 @@ class DocumentDoctrineIndexComponent < 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

2
app/components/document_doctrine_index_component/document_doctrine_index_component.html.erb

@ -10,7 +10,7 @@
<h5 style="color: darkred;"> <%= [document_title, jurisprudence.reference_number, date_or_year].join(", ") %> </h5>
<% 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| %>
<p class="mb-2 ms-3">
<% annotated_documents_title = [] %>
<% annotation.documents.each do |annotated_document| %>

4
app/components/document_doctrine_show_component/document_doctrine_show_component.html.erb

@ -6,7 +6,7 @@
</div>
<div class="col-sm-2 d-flex justify-content-end pe-0" data-controller="doctrines" data-document-id="<%= document_id %>" data-doctrine-id="<%= id %>" >
<a class="btn btn-success me-3 for-selectize-edit"data-action="click->doctrines#renderForm" data-bs-toggle="modal" data-bs-target="#doctrineModal"> Edit </a>
<a class="btn btn-success me-3 for-selectize-edit" href="<%= edit_doctrine_path(id, jurisprudence_id: document_id) %>"> Edit </a>
<a class="btn btn-danger " data-action="click->doctrines#delete" > Delete </a>
</div>
</div>
@ -85,7 +85,7 @@
<div class="row-flex">
<div class="annot-header"> <h5> Annotations </h5> </div>
<div class="" id="annotationsIndexView">
<% 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 = [] %>

Loading…
Cancel
Save