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.25.2 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.25.1 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.25.0 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.25.0.rc4 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.25.0.rc3 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.25.0.rc2 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.25.0.rc1 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.24.3 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.23.6 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.24.2 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.23.5 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.24.1 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.24.0 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.24.0.rc2 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.23.4 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.24.0.rc1 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.23.3 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.23.2 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.23.1 app/services/decidim/consultations/consultation_search.rb
decidim-consultations-0.23.1.rc1 app/services/decidim/consultations/consultation_search.rb