Class: Landable::SearchEngine

Inherits:
Object
  • Object
show all
Defined in:
app/models/landable/search_engine.rb

Direct Known Subclasses

AssetSearchEngine, PageSearchEngine

Instance Method Summary collapse

Constructor Details

#initialize(base_scope, filters, options = {}) ⇒ SearchEngine

Returns a new instance of SearchEngine.



3
4
5
6
7
8
9
10
# File 'app/models/landable/search_engine.rb', line 3

def initialize(base_scope, filters, options = {})
  @scope = base_scope

  order! options[:order]
  limit! options[:limit]

  filter_by!(filters)
end

Instance Method Details

#filter_by!(_filters) ⇒ Object



20
21
22
# File 'app/models/landable/search_engine.rb', line 20

def filter_by!(_filters)
  fail NotImplementedError
end

#limit!(limit) ⇒ Object



28
29
30
# File 'app/models/landable/search_engine.rb', line 28

def limit!(limit)
  @scope = @scope.limit(limit) if limit
end

#metaObject



16
17
18
# File 'app/models/landable/search_engine.rb', line 16

def meta
  { search: { total_results: @scope.count(:all) } }
end

#order!(order) ⇒ Object



24
25
26
# File 'app/models/landable/search_engine.rb', line 24

def order!(order)
  @scope = @scope.order(order) if order
end

#resultsObject



12
13
14
# File 'app/models/landable/search_engine.rb', line 12

def results
  @scope
end