Class: Decidim::Consultations::ConsultationSearch
- Inherits:
-
Searchlight::Search
- Object
- Searchlight::Search
- Decidim::Consultations::ConsultationSearch
- Defined in:
- app/services/decidim/consultations/consultation_search.rb
Overview
Service that encapsulates all logic related to filtering consultations.
Instance Method Summary collapse
- #base_query ⇒ Object
-
#initialize(options = {}) ⇒ ConsultationSearch
constructor
Public: Initializes the service.
-
#search_search_text ⇒ Object
Handle the search_text filter.
-
#search_state ⇒ Object
Handle the state filter.
Constructor Details
#initialize(options = {}) ⇒ ConsultationSearch
Public: Initializes the service. page - The page number to paginate the results. per_page - The number of proposals to return per page.
10 11 12 |
# File 'app/services/decidim/consultations/consultation_search.rb', line 10 def initialize( = {}) super() end |
Instance Method Details
#base_query ⇒ Object
14 15 16 |
# File 'app/services/decidim/consultations/consultation_search.rb', line 14 def base_query Decidim::Consultation.where(organization: [:organization]).published end |
#search_search_text ⇒ Object
Handle the search_text filter
19 20 21 22 23 24 25 26 27 28 |
# File 'app/services/decidim/consultations/consultation_search.rb', line 19 def search_search_text query .where("title->>'#{current_locale}' ILIKE ?", "%#{search_text}%") .or( query.where("description->>'#{current_locale}' ILIKE ?", "%#{search_text}%") ) .or( query.where("subtitle->>'#{current_locale}' ILIKE ?", "%#{search_text}%") ) end |
#search_state ⇒ Object
Handle the state filter
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/services/decidim/consultations/consultation_search.rb', line 31 def search_state case state when "active" query.active when "upcoming" query.upcoming when "finished" query.finished else # Assume all query end end |