Class: Decidim::Accountability::ResultSearch
- Inherits:
-
ResourceSearch
- Object
- ResourceSearch
- Decidim::Accountability::ResultSearch
- Defined in:
- 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 Method Summary collapse
-
#initialize(options = {}) ⇒ ResultSearch
constructor
Public: Initializes the service.
-
#search_parent_id ⇒ Object
Handle parent_id filter.
-
#search_search_text ⇒ Object
Handle the search_text filter.
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.
20 21 22 23 24 25 |
# File 'app/services/decidim/accountability/result_search.rb', line 20 def initialize( = {}) = .dup [:deep_search] = true if [:deep_search].nil? [:parent_id] = "root" if [:parent_id].nil? super(Result.all, ) end |
Instance Method Details
#search_parent_id ⇒ Object
Handle parent_id filter
35 36 37 38 39 40 41 42 43 44 |
# File 'app/services/decidim/accountability/result_search.rb', line 35 def search_parent_id parent_id = [:parent_id] parent_id = nil if parent_id == "root" if [:deep_search] query.where(parent_id: [parent_id] + children_ids(parent_id)) else query.where(parent_id: parent_id) end end |
#search_search_text ⇒ Object
Handle the search_text filter
28 29 30 31 32 |
# File 'app/services/decidim/accountability/result_search.rb', line 28 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 |