Class: Elasticated::IndexSelector

Inherits:
Object
  • Object
show all
Includes:
BlockEvaluation
Defined in:
lib/elasticated/index_selector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BlockEvaluation

#evaluate

Constructor Details

#initialize(strategy = nil, delimiters = nil) ⇒ IndexSelector

params will not be optionals in the next version



11
12
13
14
# File 'lib/elasticated/index_selector.rb', line 11

def initialize(strategy=nil, delimiters=nil)
  @strategy = strategy
  @delimiters = delimiters
end

Instance Attribute Details

#delimitersObject (readonly)

Returns the value of attribute delimiters.



8
9
10
# File 'lib/elasticated/index_selector.rb', line 8

def delimiters
  @delimiters
end

#strategyObject (readonly)

Returns the value of attribute strategy.



8
9
10
# File 'lib/elasticated/index_selector.rb', line 8

def strategy
  @strategy
end

Instance Method Details

#index_for_document(document) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/elasticated/index_selector.rb', line 23

def index_for_document(document)
  params = strategy_params_for_document document
  indices = strategy.call params
  raise "Only one index can be affected for a document indexation" if indices.count > 1
  raise "At least one index should be affected for a document indexation" if indices.count < 1
  indices.first
end

#index_for_percolator(query) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/elasticated/index_selector.rb', line 31

def index_for_percolator(query)
  params = strategy_params_for_percolator query
  indices = strategy.call params
  raise "Only one index can be affected for a percolator indexation" if indices.count > 1
  raise "At least one index should be affected for a percolator indexation" if indices.count < 1
  indices.first
end

#indices_for_query(query, opts = {}) ⇒ Object



16
17
18
19
20
21
# File 'lib/elasticated/index_selector.rb', line 16

def indices_for_query(query, opts={})
  strategy_params = Elasticated.strategy_params_for_query_service.strategy_params_for_query delimiters, query, opts
  indices = strategy.call strategy_params
  raise "At least one index should be affected for a search" if indices.count < 1
  indices
end