Browse Source

Enhance `searchable` for `jurisprudence`, `doctrine`, and `annotation`

pull/110/head
alexdbondoc17 4 years ago
parent
commit
f14998b01c
  1. 4
      app/controllers/concerns/annotation_search.rb
  2. 6
      app/controllers/concerns/doctrine_search.rb
  3. 6
      app/models/annotation.rb
  4. 7
      app/models/cdao/document.rb
  5. 2
      app/models/cdao/jurisprudence.rb
  6. 4
      app/models/doctrine.rb
  7. 10
      app/models/doctrine_jurisprudence.rb

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

6
app/models/annotation.rb

@ -11,6 +11,8 @@ class Annotation < ApplicationRecord
has_many :annotation_annomarks, dependent: :destroy
has_many :annomarks, through: :annotation_annomarks
validates :content, presence: true
def documents
annotation_documents.collect(&:document)
end
@ -33,6 +35,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

@ -179,7 +179,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

Loading…
Cancel
Save