Class: Elasticity::MultiSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticity/multi_search.rb

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ MultiSearch

Returns a new instance of MultiSearch

Yields:

  • (_self)

Yield Parameters:


3
4
5
6
7
# File 'lib/elasticity/multi_search.rb', line 3

def initialize
  @searches = {}
  @mappers  = {}
  yield self if block_given?
end

Instance Method Details

#[](name) ⇒ Object


25
26
27
28
# File 'lib/elasticity/multi_search.rb', line 25

def [](name)
  @results ||= fetch
  @results[name]
end

#add(name, search, documents: nil, active_records: nil) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/elasticity/multi_search.rb', line 9

def add(name, search, documents: nil, active_records: nil)
  if !documents.nil? && !active_records.nil?
    raise ArgumentError, "you can only pass either :documents or :active_records as an option"
  elsif documents.nil? && active_records.nil?
    raise ArgumentError, "you need to provide either :documents or :active_records as an option"
  end

  @searches[name] = {
    search_definition: search.search_definition,
    documents: documents,
    active_records: active_records
  }

  name
end