Sha256: 93a9b187fb2065a3d080e3b2b44adcbe15d3965f42ff6e8dc595c7178c4ef7af
Contents?: true
Size: 1.27 KB
Versions: 13
Compression:
Stored size: 1.27 KB
Contents
# frozen_string_literal: true module Decidim module Votings # Service that encapsulates all logic related to filtering votings. class VotingSearch < Searchlight::Search # Public: Initializes the service. # page - The page number to paginate the results. # per_page - The number of proposals to return per page. def initialize(options = {}) super(options) end def base_query Decidim::Votings::Voting.where(organization: options[:organization]).published end # Handle the search_text filter def search_search_text query .where("title->>'#{current_locale}' ILIKE ?", "%#{search_text}%") .or( query.where("description->>'#{current_locale}' ILIKE ?", "%#{search_text}%") ) end # Handle the state filter 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 private def current_locale I18n.locale.to_s end end end end
Version data entries
13 entries across 13 versions & 1 rubygems