Sha256: c43d3587f362cb521061be9a4b10de76dd2d0dd62fc28ded3e3adced163e7e6b

Contents?: true

Size: 1.29 KB

Versions: 51

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module Decidim
  module Consultations
    # Service that encapsulates all logic related to filtering consultations.
    class ConsultationSearch < 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::Consultation.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}%")
          )
          .or(
            query.where("subtitle->>'#{current_locale}' ILIKE ?", "%#{search_text}%")
          )
      end

      # Handle the state filter
      def search_state
        case state
        when "active"
          query.active
        when "upcoming"
          query.upcoming
        when "finished"
          query.finished
        else # Assume all
          query
        end
      end

      private

      def current_locale
        I18n.locale.to_s
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
decidim-consultations-0.23.0 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.22.0 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.21.0 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.20.1 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.20.0 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.19.1 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.18.1 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.19.0 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.17.2 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.18.0 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.17.1 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.16.1 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.17.0 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.16.0 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.15.2 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.15.1 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.15.0 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.14.4 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.14.3 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.14.2 app/services/decidim/consultations/consultation_search.rb