Browse Source

Improve `jurisprudence#search`

pull/69/head
alexdbondoc17 4 years ago
parent
commit
f1fa322c4f
  1. 12
      app/components/document_advanced_search_component/document_advanced_search_component.html.erb
  2. 12
      app/controllers/concerns/jurisprudence_search.rb
  3. 4
      app/controllers/documents_controller.rb
  4. 8
      app/models/cdao/jurisprudence.rb
  5. 2
      app/views/decisions/index.html.erb

12
app/components/document_advanced_search_component/document_advanced_search_component.html.erb

@ -13,24 +13,26 @@
<%= text_field_tag :title, params[:short_title], class: "form-control mb-0" %> <%= text_field_tag :title, params[:short_title], class: "form-control mb-0" %>
</div> </div>
<% if opts[:is_decisions_index].present? %>
<div class="mb-2"> <div class="mb-2">
<label for="exampleFormControlInput1" class="form-label text-white">Ponente</label> <label for="exampleFormControlInput1" class="form-label text-white">Ponente</label>
<%= text_field_tag :title, params[:short_title], class: "form-control mb-0" %> <%= text_field_tag :ponente, params[:ponente], class: "form-control mb-0" %>
</div> </div>
<div class="mb-2"> <div class="mb-2">
<label for="exampleFormControlInput1" class="form-label text-white">Syllabus</label> <label for="exampleFormControlInput1" class="form-label text-white">Syllabus</label>
<%= text_field_tag :title, params[:short_title], class: "form-control mb-0" %> <%= text_field_tag :syllabus, params[:syllabus], class: "form-control mb-0" %>
</div> </div>
<div class="d-flex align-items-end"> <% end %>
<div class="d-flex align-items-end">
<div class="mb-2 w-100 pe-2"> <div class="mb-2 w-100 pe-2">
<label for="exampleFormControlInput1" class="form-label text-white">Year</label> <label for="exampleFormControlInput1" class="form-label text-white">Year</label>
<%= select_tag :year, options_for_select(years, params[:year]), class: "form-select", include_blank: true %> <%= select_tag :year_start, options_for_select(years, params[:year_start]), class: "form-select", include_blank: true %>
</div> </div>
<div class="mb-2 w-100 ps-2"> <div class="mb-2 w-100 ps-2">
<%= select_tag :year, options_for_select(years, params[:year]), class: "form-select", include_blank: true %> <%= select_tag :year_end, options_for_select(years, params[:year_end]), class: "form-select", include_blank: true %>
</div> </div>
</div> </div>
<hr class="simple mb-0"> <hr class="simple mb-0">

12
app/controllers/concerns/jurisprudence_search.rb

@ -5,11 +5,17 @@ module JurisprudenceSearch
search = Cdao::Jurisprudence.search do search = Cdao::Jurisprudence.search do
fulltext search_params[:q], fields: fulltext_fields if search_params[:q].present? fulltext search_params[:q], fields: fulltext_fields if search_params[:q].present?
fulltext_fields.each do |field| %i[reference_number title short_title ponente syllabus].each do |field|
fulltext search_params[field], fields: [field] if search_params[field].present? fulltext search_params[field], fields: [field], query_phrase_slop: 1 if search_params[field].present?
end end
with(:year, search_params[:year].to_i) if search_params[:year].present? if search_params[:year_start].present? && search_params[:year_end].present?
with(:year).between(search_params[:year_start].to_i..search_params[:year_start].to_i)
end
if search_params[:year_start].present? && search_params[:year_end].blank?
with(:year, search_params[:year_start].to_i)
end
with(:subject_ids).any_of(search_params[:subject_ids].split(",").map(&:strip).map(&:to_i)) if search_params[:subject_ids].present? with(:subject_ids).any_of(search_params[:subject_ids].split(",").map(&:strip).map(&:to_i)) if search_params[:subject_ids].present?

4
app/controllers/documents_controller.rb

@ -33,8 +33,8 @@ class DocumentsController < ApplicationController
private private
def search_params def search_params
params.permit(:reference_number, :title, :short_title, params.permit(:reference_number, :title, :short_title, :ponente, :syllabus,
:year, :citation_finder, :subject_ids, :year_start, :year_end, :citation_finder, :subject_ids,
:q, :page, :per_page) :q, :page, :per_page)
end end
end end

8
app/models/cdao/jurisprudence.rb

@ -132,15 +132,21 @@ class Cdao::Jurisprudence < Cdao::Base
text :reference_number, stored: true text :reference_number, stored: true
text :title, stored: true text :title, stored: true
text :short_title, stored: true text :short_title, stored: true
text :ponente, stored: true
text :syllabus, stored: true
string :reference_number string :reference_number
string :ponente
string :syllabus
string :title do string :title do
(title.present? ? title.first(32760).strip : short_title || "").titleize (title.present? ? title.first(32760).strip : short_title || "").titleize
end end
string :short_title do string :short_title do
(short_title.presence || title.first(32760).strip || "").titleize (short_title.presence || title.first(32760).strip || "").titleize
end end
string :citation_finders_names, multiple: true string :citation_finders_names, multiple: true do
citation_finders_names
end
date :doc_date date :doc_date
date :search_doc_date do date :search_doc_date do

2
app/views/decisions/index.html.erb

@ -1,7 +1,7 @@
<div class="container-fluid row p-0 m-0"> <div class="container-fluid row p-0 m-0">
<div class="container col-xs-12 col-sm-12 col-md-3 col-lg-3 col-xl-3" > <div class="container col-xs-12 col-sm-12 col-md-3 col-lg-3 col-xl-3" >
<div class="advanced-search-box"> <div class="advanced-search-box">
<%= render(DocumentAdvancedSearchComponent.new(current_user: current_user, opts: {})) %> <%= render(DocumentAdvancedSearchComponent.new(current_user: current_user, opts: { is_decisions_index: true })) %>
</div> </div>
</div> </div>
<div class="container col-xs-12 col-sm-12 col-md-9 col-lg-9 col-xl-9"> <div class="container col-xs-12 col-sm-12 col-md-9 col-lg-9 col-xl-9">

Loading…
Cancel
Save