Class: Decidim::ParticipatorySpaceSearch

Inherits:
Searchlight::Search
  • Object
show all
Defined in:
app/services/decidim/participatory_space_search.rb

Overview

This is the base class to be used by other ParticipatorySpace search services Searchlight documentation: github.com/nathanl/searchlight

Instance Method Summary collapse

Constructor Details

#initialize(scope, options = {}) ⇒ ParticipatorySpaceSearch

Initialize the Searchlight::Search base class with the options provided.

scope - The scope used to create the base query options - A hash of options to modify the search. These options will be

converted to methods by SearchLight so they can be used on filter
methods. (Default {})


13
14
15
16
# File 'app/services/decidim/participatory_space_search.rb', line 13

def initialize(scope, options = {})
  super(options)
  @scope = scope
end

Instance Method Details

#base_queryObject

Creates the SearchLight base query.



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

def base_query
  @scope = @scope.where(organization: organization)
  @scope = @scope.published if @scope.respond_to?(:published)
  @scope = @scope.visible_for(current_user) if @scope.respond_to?(:visible_for)
end

#search_area_idObject

Handle the area_id filter



40
41
42
# File 'app/services/decidim/participatory_space_search.rb', line 40

def search_area_id
  query.includes(:area).where(decidim_area_id: area_id)
end

#search_scope_idObject

Handles the scope_id filter.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/services/decidim/participatory_space_search.rb', line 26

def search_scope_id
  clean_scope_ids = if scope_id.is_a?(Hash)
                      scope_id.values
                    else
                      [scope_id].flatten
                    end
  conditions = []
  conditions << "decidim_scope_id IS NULL" if clean_scope_ids.delete("global")
  conditions.concat(["? = ANY(decidim_scopes.part_of)"] * clean_scope_ids.count) if clean_scope_ids.any?

  query.includes(:scope).references(:decidim_scopes).where(conditions.join(" OR "), *clean_scope_ids.map(&:to_i))
end