Class: Decidim::Consultations::ConsultationSearch

Inherits:
Searchlight::Search
  • Object
show all
Defined in:
decidim-consultations/app/services/decidim/consultations/consultation_search.rb

Overview

Service that encapsulates all logic related to filtering consultations.

Instance Method Summary collapse

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 'decidim-consultations/app/services/decidim/consultations/consultation_search.rb', line 10

def initialize(options = {})
  super(options)
end

Instance Method Details

#base_queryObject


14
15
16
# File 'decidim-consultations/app/services/decidim/consultations/consultation_search.rb', line 14

def base_query
  Decidim::Consultation.where(organization: options[:organization]).published
end

#search_search_textObject

Handle the search_text filter


19
20
21
22
23
24
25
26
27
28
# File 'decidim-consultations/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_stateObject

Handle the state filter


31
32
33
34
35
36
37
38
39
40
41
42
# File 'decidim-consultations/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