Class: Elasticity::MultiSearch

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

Instance Method Summary collapse

Constructor Details

#initialize(msearch_args = {}) {|_self| ... } ⇒ MultiSearch

Returns a new instance of MultiSearch.

Yields:

  • (_self)

Yield Parameters:



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

def initialize(msearch_args = {})
  @results  = {}
  @searches = {}
  @mappers  = {}
  @msearch_args = msearch_args
  yield self if block_given?
end

Instance Method Details

#[](name) ⇒ Object



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

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

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



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

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