Class: Decidim::Accountability::ResultSearch

Inherits:
ResourceSearch
  • Object
show all
Defined in:
decidim-accountability/app/services/decidim/accountability/result_search.rb

Overview

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

Instance Attribute Summary

Attributes inherited from ResourceSearch

#component, #organization, #user

Instance Method Summary collapse

Methods inherited from ResourceSearch

#base_query, #results, #search_category_id, #search_origin, #search_scope_id, #search_search_text, text_search_fields

Constructor Details

#initialize(options = {}) ⇒ ResultSearch

Public: Initializes the service.

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 {})
* component - A Decidim::Component to get the results from.
* organization - A Decidim::Organization object.
* parent_id - The parent ID of the result. The value is forced to false to force
              the filter execution when the value is nil
* deep_search - Whether to perform the search on all children levels or just the
                first one. True by default.

22
23
24
25
26
27
# File 'decidim-accountability/app/services/decidim/accountability/result_search.rb', line 22

def initialize(options = {})
  options = options.dup
  options[:deep_search] = true if options[:deep_search].nil?
  options[:parent_id] = "root" if options[:parent_id].nil?
  super(Result.all, options)
end

Instance Method Details

#search_parent_idObject

Handle parent_id filter


30
31
32
33
34
35
36
37
38
39
# File 'decidim-accountability/app/services/decidim/accountability/result_search.rb', line 30

def search_parent_id
  parent_id = options[:parent_id]
  parent_id = nil if parent_id == "root"

  if options[:deep_search]
    query.where(parent_id: [parent_id] + children_ids(parent_id))
  else
    query.where(parent_id: parent_id)
  end
end