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.



13
14
15
# File 'app/services/decidim/budgets/project_search.rb', line 13

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

Instance Method Details

#base_queryObject

Creates the SearchLight base query.



18
19
20
21
22
23
# File 'app/services/decidim/budgets/project_search.rb', line 18

def base_query
  raise "Missing budget" unless budget
  raise "Missing component" unless component

  @scope.where(budget: budget)
end

#resultsObject

Returns the random projects for the current page.



26
27
28
# File 'app/services/decidim/budgets/project_search.rb', line 26

def results
  Project.where(id: super.pluck(:id)).includes([:scope, :component, :attachments, :category])
end