Class: Stretchy::Results::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/stretchy/results/base.rb

Direct Known Subclasses

NullResults

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clause) ⇒ Base

Returns a new instance of Base.



11
12
13
14
# File 'lib/stretchy/results/base.rb', line 11

def initialize(clause)
  @clause     = clause
  @index_name = clause.index_name || Stretchy.index_name
end

Instance Attribute Details

#clauseObject (readonly)

Returns the value of attribute clause.



7
8
9
# File 'lib/stretchy/results/base.rb', line 7

def clause
  @clause
end

#index_nameObject (readonly)

Returns the value of attribute index_name.



7
8
9
# File 'lib/stretchy/results/base.rb', line 7

def index_name
  @index_name
end

Instance Method Details

#hitsObject Also known as: results



36
37
38
39
40
41
# File 'lib/stretchy/results/base.rb', line 36

def hits
  @hits ||= response['hits']['hits'].map do |hit|
    merge_fields = hit.reject{|field, _| field == '_source' }
    hit['_source'].merge(merge_fields)
  end
end

#idsObject



32
33
34
# File 'lib/stretchy/results/base.rb', line 32

def ids
  @ids ||= response['hits']['hits'].map{|h| h['_id'] =~ /\d+(\.\d+)?/ ? h['_id'].to_i : h['_id'] }
end

#limitObject



16
17
18
# File 'lib/stretchy/results/base.rb', line 16

def limit
  clause.get_limit
end

#max_scoreObject



56
57
58
# File 'lib/stretchy/results/base.rb', line 56

def max_score
  @max_score ||= response['hits']['max_score']
end

#offsetObject



20
21
22
# File 'lib/stretchy/results/base.rb', line 20

def offset
  clause.get_offset
end

#requestObject



24
25
26
# File 'lib/stretchy/results/base.rb', line 24

def request
  @request ||= {query: clause.to_search}
end

#responseObject



28
29
30
# File 'lib/stretchy/results/base.rb', line 28

def response
  @response ||= Stretchy.search(type: type, body: request, from: offset, size: limit)
end

#shardsObject



48
49
50
# File 'lib/stretchy/results/base.rb', line 48

def shards
  @shards ||= response['_shards']
end

#tookObject



44
45
46
# File 'lib/stretchy/results/base.rb', line 44

def took
  @took ||= response['took']
end

#totalObject



52
53
54
# File 'lib/stretchy/results/base.rb', line 52

def total
  @total ||= response['hits']['total']
end