Class: Decidim::ResourceSearch

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

Overview

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

Instance Method Summary collapse

Constructor Details

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

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 {})


12
13
14
15
# File 'app/services/decidim/resource_search.rb', line 12

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

Instance Method Details

#base_queryObject

Creates the SearchLight base query. Check if the option feature was provided.



19
20
21
22
23
24
25
26
27
# File 'app/services/decidim/resource_search.rb', line 19

def base_query
  # raise order_start_time.inspect
  raise "Missing feature" unless feature

  @scope
    .page(options[:page] || 1)
    .per(options[:per_page] || 12)
    .where(feature: feature)
end

#search_category_idObject

Handle the category_id filter



30
31
32
# File 'app/services/decidim/resource_search.rb', line 30

def search_category_id
  query.where(decidim_category_id: category_ids)
end