Class: Elastic::Nodes::Search

Inherits:
Base
  • Object
show all
Includes:
Concerns::Aggregable, Concerns::HitProvider
Defined in:
lib/elastic/nodes/search.rb

Instance Attribute Summary collapse

Attributes included from Concerns::HitProvider

#size, #source

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Aggregable

#aggregate, #aggregations, #aggregations=, #has_aggregations?

Methods inherited from Base

#==

Methods included from Support::Traversable

#pick

Instance Attribute Details

#offsetObject

Returns the value of attribute offset.



6
7
8
# File 'lib/elastic/nodes/search.rb', line 6

def offset
  @offset
end

#queryObject

Returns the value of attribute query.



6
7
8
# File 'lib/elastic/nodes/search.rb', line 6

def query
  @query
end

Class Method Details

.build(_query) ⇒ Object



8
9
10
# File 'lib/elastic/nodes/search.rb', line 8

def self.build(_query)
  new.tap { |n| n.query = _query }
end

Instance Method Details

#cloneObject



25
26
27
# File 'lib/elastic/nodes/search.rb', line 25

def clone
  prepare_clone(super, @query.clone)
end

#handle_result(_raw, _formatter) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/elastic/nodes/search.rb', line 33

def handle_result(_raw, _formatter)
  Elastic::Results::Root.new(
    _raw['hits'] ? prepare_hits(_raw['hits']['hits'], _formatter) : [],
    _raw['hits'] ? _raw['hits']['total'] : 0,
    _raw['aggregations'] ? load_aggs_results(_raw['aggregations'], _formatter) : {}
  )
end

#render(_options = {}) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/elastic/nodes/search.rb', line 17

def render(_options = {})
  { "query" => @query.render(_options) }.tap do |hash|
    hash["from"] = @offset if offset && offset > 0
    render_hit_options(hash)
    render_aggs(hash, _options)
  end
end

#simplifyObject



29
30
31
# File 'lib/elastic/nodes/search.rb', line 29

def simplify
  prepare_clone(super, @query.simplify)
end

#traverse(&_block) ⇒ Object



12
13
14
15
# File 'lib/elastic/nodes/search.rb', line 12

def traverse(&_block)
  super
  @query.traverse(&_block)
end