Class: Decidim::Debates::DebateSearch
- Inherits:
-
ResourceSearch
- Object
- ResourceSearch
- Decidim::Debates::DebateSearch
- Defined in:
- app/services/decidim/debates/debate_search.rb
Overview
This class handles search and filtering of debates. Needs a ‘current_component` param with a `Decidim::Component` in order to find the debates.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ DebateSearch
constructor
Public: Initializes the service.
-
#search_origin ⇒ Object
Handle the origin filter The ‘official’ debates don’t have an author ID.
-
#search_search_text ⇒ Object
Handle the search_text filter.
Constructor Details
#initialize(options = {}) ⇒ DebateSearch
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.
13 14 15 |
# File 'app/services/decidim/debates/debate_search.rb', line 13 def initialize( = {}) super(Debate.not_hidden, ) end |
Instance Method Details
#search_origin ⇒ Object
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_text ⇒ Object
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 |