Class: Decidim::Budgets::ProjectSearch
- Inherits:
-
ResourceSearch
- Object
- ResourceSearch
- Decidim::Budgets::ProjectSearch
- Defined in:
- app/services/decidim/budgets/project_search.rb
Overview
This class handles search and filtering of projects. Needs a ‘current_feature` param with a `Decidim::Feature` in order to find the projects.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ProjectSearch
constructor
Public: Initializes the service.
-
#random_seed ⇒ Object
Returns the random seed used to randomize the proposals.
-
#results ⇒ Object
Returns the random projects for the current page.
-
#search_search_text ⇒ Object
Handle the search_text filter.
Constructor Details
#initialize(options = {}) ⇒ ProjectSearch
Public: Initializes the service. feature - A Decidim::Feature to get the projects from.
11 12 13 14 |
# File 'app/services/decidim/budgets/project_search.rb', line 11 def initialize( = {}) super(Project.all, ) @random_seed = [:random_seed].to_f end |
Instance Method Details
#random_seed ⇒ Object
Returns the random seed used to randomize the proposals.
32 33 34 35 |
# File 'app/services/decidim/budgets/project_search.rb', line 32 def random_seed @random_seed = (rand * 2 - 1) if @random_seed == 0.0 || @random_seed > 1 || @random_seed < -1 @random_seed end |
#results ⇒ Object
Returns the random projects for the current page.
24 25 26 27 28 29 |
# File 'app/services/decidim/budgets/project_search.rb', line 24 def results @projects ||= Project.transaction do Project.connection.execute("SELECT setseed(#{Project.connection.quote(random_seed)})") super.reorder("RANDOM()").load end end |
#search_search_text ⇒ Object
Handle the search_text filter
17 18 19 20 21 |
# File 'app/services/decidim/budgets/project_search.rb', line 17 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 |