Class: Decidim::Debates::DebateSearch

Inherits:
ResourceSearch
  • Object
show all
Defined in:
app/services/decidim/debates/debate_search.rb

Overview

This class handles search and filtering of debates. Needs a ‘current_feature` param with a `Decidim::Feature` in order to find the debates.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DebateSearch

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.



13
14
15
# File 'app/services/decidim/debates/debate_search.rb', line 13

def initialize(options = {})
  super(Debate.not_hidden, options)
end

Instance Method Details

#search_originObject

Handle the origin filter The ‘official’ debates don’t have an author ID



27
28
29
30
31
32
33
34
35
# File 'app/services/decidim/debates/debate_search.rb', line 27

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

#search_search_textObject

Handle the search_text filter. We have to cast the JSONB columns into a ‘text` type so that we can search.



19
20
21
22
23
# File 'app/services/decidim/debates/debate_search.rb', line 19

def search_search_text
  query
    .where("title::text ILIKE ?", "%#{search_text}%")
    .or(query.where("description::text ILIKE ?", "%#{search_text}%"))
end