Class: Decidim::Initiatives::InitiativeSearch
- Inherits:
-
Searchlight::Search
- Object
- Searchlight::Search
- Decidim::Initiatives::InitiativeSearch
- Includes:
- CurrentLocale
- Defined in:
- app/services/decidim/initiatives/initiative_search.rb
Overview
Service that encapsulates all logic related to filtering initiatives.
Instance Method Summary collapse
- #base_query ⇒ Object
-
#initialize(options = {}) ⇒ InitiativeSearch
constructor
Public: Initializes the service.
- #search_author ⇒ Object
- #search_scope_id ⇒ Object
-
#search_search_text ⇒ Object
Handle the search_text filter.
-
#search_state ⇒ Object
Handle the state filter.
- #search_type ⇒ Object
Methods included from CurrentLocale
Constructor Details
#initialize(options = {}) ⇒ InitiativeSearch
Public: Initializes the service. page - The page number to paginate the results. per_page - The number of proposals to return per page.
12 13 14 |
# File 'app/services/decidim/initiatives/initiative_search.rb', line 12 def initialize( = {}) super() end |
Instance Method Details
#base_query ⇒ Object
16 17 18 19 20 |
# File 'app/services/decidim/initiatives/initiative_search.rb', line 16 def base_query Decidim::Initiative .includes(scoped_type: [:scope]) .where(organization: [:organization]) end |
#search_author ⇒ Object
52 53 54 55 56 57 58 |
# File 'app/services/decidim/initiatives/initiative_search.rb', line 52 def if == "myself" && [:current_user] query.where(decidim_author_id: [:current_user].id) else query end end |
#search_scope_id ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'app/services/decidim/initiatives/initiative_search.rb', line 60 def search_scope_id return if scope_id.nil? query .joins(:scoped_type) .where( "decidim_initiatives_type_scopes.decidim_scopes_id": scope_id ) end |
#search_search_text ⇒ Object
Handle the search_text filter
23 24 25 26 27 28 29 30 31 32 |
# File 'app/services/decidim/initiatives/initiative_search.rb', line 23 def search_search_text query .where("title->>'#{current_locale}' ILIKE ?", "%#{search_text}%") .or( query.where( "description->>'#{current_locale}' ILIKE ?", "%#{search_text}%" ) ) end |
#search_state ⇒ Object
Handle the state filter
35 36 37 38 39 40 41 42 |
# File 'app/services/decidim/initiatives/initiative_search.rb', line 35 def search_state case state when "closed" query.closed else # Assume open query.open end end |
#search_type ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/services/decidim/initiatives/initiative_search.rb', line 44 def search_type return query if type == "all" types = InitiativesTypeScope.where(decidim_initiatives_types_id: type).pluck(:id) query.where(scoped_type: types) end |