Sha256: 3997db07b56d285998af4f8346501d61fb8955f06a24be42ef6af192447ef195
Contents?: true
Size: 1.26 KB
Versions: 4
Compression:
Stored size: 1.26 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("decidim_debates_debates.title::text ILIKE ?", "%#{search_text}%") .or(query.where("decidim_debates_debates.description::text ILIKE ?", "%#{search_text}%")) end # Handle the origin filter def search_origin if origin == "official" query.where(author: component.organization) elsif origin == "citizens" query.where.not(decidim_author_type: "Decidim::Organization") else # Assume 'all' query end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems