Sha256: e8930920334b64da342c38fbeca8f337fec01ba5777813b246dd134dfa16d7e1
Contents?: true
Size: 1.23 KB
Versions: 6
Compression:
Stored size: 1.23 KB
Contents
# frozen_string_literal: true module Decidim module Debates # This class handles search and filtering of debates. Needs a # `current_feature` param with a `Decidim::Feature` in order to # find the debates. class DebateSearch < ResourceSearch # Public: Initializes the service. # feature - A Decidim::Feature 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
6 entries across 6 versions & 1 rubygems