Class: Elasticity::Search::LazySearch

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/elasticity/search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, search_definition, &mapper) ⇒ LazySearch


76
77
78
79
80
# File 'lib/elasticity/search.rb', line 76

def initialize(client, search_definition, &mapper)
  @client            = client
  @search_definition = search_definition
  @mapper            = mapper
end

Instance Attribute Details

#search_definitionObject

Returns the value of attribute search_definition


74
75
76
# File 'lib/elasticity/search.rb', line 74

def search_definition
  @search_definition
end

Instance Method Details

#blank?Boolean


86
87
88
# File 'lib/elasticity/search.rb', line 86

def blank?
  empty?
end

#empty?Boolean


82
83
84
# File 'lib/elasticity/search.rb', line 82

def empty?
  total == 0
end

#search_resultsObject


98
99
100
101
102
103
104
105
106
107
108
# File 'lib/elasticity/search.rb', line 98

def search_results
  return @search_results if defined?(@search_results)

  hits = response["hits"]["hits"]

  @search_results = if @mapper.nil?
    hits
  else
    hits.map { |hit| @mapper.(hit) }
  end
end

#suggestionsObject


94
95
96
# File 'lib/elasticity/search.rb', line 94

def suggestions
  response["hits"]["suggest"] ||= {}
end

#totalObject


90
91
92
# File 'lib/elasticity/search.rb', line 90

def total
  response["hits"]["total"]
end