Class: Decidim::Budgets::ProjectSearch

Inherits:
ResourceSearch
  • Object
show all
Defined in:
app/services/decidim/budgets/project_search.rb

Overview

This class handles search and filtering of projects. Needs a ‘current_component` param with a `Decidim::Component` in order to find the projects.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ProjectSearch

Public: Initializes the service. component - A Decidim::Component to get the projects from.



11
12
13
# File 'app/services/decidim/budgets/project_search.rb', line 11

def initialize(options = {})
  super(Project.all, options)
end

Instance Method Details

#resultsObject

Returns the random projects for the current page.



23
24
25
# File 'app/services/decidim/budgets/project_search.rb', line 23

def results
  Project.where(id: super.pluck(:id))
end

#search_search_textObject

Handle the search_text filter



16
17
18
19
20
# File 'app/services/decidim/budgets/project_search.rb', line 16

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