Class: Decidim::Budgets::ProjectSearch

Inherits:
ResourceSearch
  • Object
show all
Defined in:
decidim-budgets/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 Attribute Summary

Attributes inherited from ResourceSearch

#component, #organization, #user

Instance Method Summary collapse

Methods inherited from ResourceSearch

#search_category_id, #search_origin, #search_scope_id, #search_search_text, text_search_fields

Constructor Details

#initialize(options = {}) ⇒ ProjectSearch

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


13
14
15
# File 'decidim-budgets/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 'decidim-budgets/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 'decidim-budgets/app/services/decidim/budgets/project_search.rb', line 26

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