Class: Decidim::Votings::VotingSearch
- Inherits:
-
Searchlight::Search
- Object
- Searchlight::Search
- Decidim::Votings::VotingSearch
- Defined in:
- app/services/decidim/votings/voting_search.rb
Overview
Service that encapsulates all logic related to filtering votings.
Instance Method Summary collapse
- #base_query ⇒ Object
-
#initialize(options = {}) ⇒ VotingSearch
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 = {}) ⇒ VotingSearch
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/votings/voting_search.rb', line 10 def initialize( = {}) super() end |
Instance Method Details
#base_query ⇒ Object
14 15 16 |
# File 'app/services/decidim/votings/voting_search.rb', line 14 def base_query Decidim::Votings::Voting.where(organization: [:organization]).published end |
#search_search_text ⇒ Object
Handle the search_text filter
19 20 21 22 23 24 25 |
# File 'app/services/decidim/votings/voting_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}%") ) end |
#search_state ⇒ Object
Handle the state filter
28 29 30 31 32 33 34 35 36 37 |
# File 'app/services/decidim/votings/voting_search.rb', line 28 def search_state active = state.member?("active") ? query.active : nil upcoming = state.member?("upcoming") ? query.upcoming : nil finished = state.member?("finished") ? query.finished : nil query .where(id: upcoming) .or(query.where(id: active)) .or(query.where(id: finished)) end |