Sha256: 3b280338afd2222aa687965ca58ecc183604a9fe28d42b07b500f3926f2e3ee6

Contents?: true

Size: 1.34 KB

Versions: 12

Compression:

Stored size: 1.34 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(Arel.sql("title->>'#{current_locale}' ILIKE ?").to_s, "%#{search_text}%")
          .or(
            query.where(Arel.sql("description->>'#{current_locale}' ILIKE ?").to_s, "%#{search_text}%")
          )
          .or(
            query.where(Arel.sql("subtitle->>'#{current_locale}' ILIKE ?").to_s, "%#{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

12 entries across 12 versions & 1 rubygems

Version Path
decidim-consultations-0.26.10 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.26.9 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.26.8 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.26.7 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.26.5 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.26.4 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.26.3 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.26.2 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.26.1 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.26.0 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.26.0.rc2 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.26.0.rc1 app/services/decidim/consultations/consultation_search.rb