Sha256: 8a772b073c32216f6241431232e2c95faf35b56dc9c9a732bbc58158eabf8a0d

Contents?: true

Size: 1.24 KB

Versions: 14

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Decidim
  module Debates
    # This class handles search and filtering of debates. Needs a
    # `current_component` param with a `Decidim::Component` in order to
    # find the debates.
    class DebateSearch < ResourceSearch
      # Public: Initializes the service.
      # component     - A Decidim::Component to get the debates from.
      # page        - The page number to paginate the results.
      # per_page    - The number of proposals to return per page.
      def initialize(options = {})
        super(Debate.not_hidden, options)
      end

      # Handle the search_text filter. We have to cast the JSONB columns
      # into a `text` type so that we can search.
      def search_search_text
        query
          .where("title::text ILIKE ?", "%#{search_text}%")
          .or(query.where("description::text ILIKE ?", "%#{search_text}%"))
      end

      # Handle the origin filter
      # The 'official' debates don't have an author ID
      def search_origin
        if origin == "official"
          query.where(decidim_author_id: nil)
        elsif origin == "citizens"
          query.where.not(decidim_author_id: nil)
        else # Assume 'all'
          query
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
decidim-debates-0.14.4 app/services/decidim/debates/debate_search.rb
decidim-debates-0.14.3 app/services/decidim/debates/debate_search.rb
decidim-debates-0.14.2 app/services/decidim/debates/debate_search.rb
decidim-debates-0.14.1 app/services/decidim/debates/debate_search.rb
decidim-debates-0.13.1 app/services/decidim/debates/debate_search.rb
decidim-debates-0.12.2 app/services/decidim/debates/debate_search.rb
decidim-debates-0.13.0 app/services/decidim/debates/debate_search.rb
decidim-debates-0.12.1 app/services/decidim/debates/debate_search.rb
decidim-debates-0.13.0.pre1 app/services/decidim/debates/debate_search.rb
decidim-debates-0.12.0 app/services/decidim/debates/debate_search.rb
decidim-debates-0.11.2 app/services/decidim/debates/debate_search.rb
decidim-debates-0.12.0.pre app/services/decidim/debates/debate_search.rb
decidim-debates-0.11.1 app/services/decidim/debates/debate_search.rb
decidim-debates-0.11.0.pre1 app/services/decidim/debates/debate_search.rb