Class: ElasticsearchDslBuilder::DSL::Search::Queries::GeoBoundingBox

Inherits:
Query
  • Object
show all
Defined in:
lib/elasticsearch_dsl_builder/dsl/search/queries/geo_bounding_box.rb

Instance Attribute Summary

Attributes inherited from Query

#query

Instance Method Summary collapse

Constructor Details

#initialize(field) ⇒ GeoBoundingBox

Returns a new instance of GeoBoundingBox.



6
7
8
9
10
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/geo_bounding_box.rb', line 6

def initialize(field)
  @type = :geo_bounding_box
  field(field)
  super()
end

Instance Method Details

#bottom_right(lat, lon) ⇒ Object

Raises:

  • (ArgumentError)


32
33
34
35
36
37
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/geo_bounding_box.rb', line 32

def bottom_right(lat, lon)
  raise ArgumentError, 'lat must be numeric' unless lat.is_a?(Numeric)
  raise ArgumentError, 'lon must be numeric' unless lon.is_a?(Numeric)
  @bottom_right = { lat: lat, lon: lon }
  self
end

#bottom_right_geohash(geohash) ⇒ Object

Raises:

  • (ArgumentError)


39
40
41
42
43
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/geo_bounding_box.rb', line 39

def bottom_right_geohash(geohash)
  raise ArgumentError, 'geohash must be a String' unless geohash.instance_of?(String)
  @bottom_right = geohash
  self
end

#field(field) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
16
17
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/geo_bounding_box.rb', line 12

def field(field)
  field_valid = field.instance_of?(String) || field.instance_of?(Symbol)
  raise ArgumentError, 'field must be a String or Symbol' unless field_valid
  @field = field.to_sym
  self
end

#to_hashObject

Raises:

  • (ArgumentError)


51
52
53
54
55
56
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/geo_bounding_box.rb', line 51

def to_hash
  raise ArgumentError, 'must have set bounding box' if @top_left.nil? || @bottom_right.nil?
  @query = { @field => { top_left: @top_left, bottom_right: @bottom_right } }
  @query.update(type: @geo_type) if @geo_type
  super
end

#top_left(lat, lon) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/geo_bounding_box.rb', line 19

def top_left(lat, lon)
  raise ArgumentError, 'lat must be numeric' unless lat.is_a?(Numeric)
  raise ArgumentError, 'lon must be numeric' unless lon.is_a?(Numeric)
  @top_left = { lat: lat, lon: lon }
  self
end

#top_left_geohash(geohash) ⇒ Object

Raises:

  • (ArgumentError)


26
27
28
29
30
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/geo_bounding_box.rb', line 26

def top_left_geohash(geohash)
  raise ArgumentError, 'geohash must be a String' unless geohash.instance_of?(String)
  @top_left = geohash
  self
end

#type(type) ⇒ Object

Raises:

  • (ArgumentError)


45
46
47
48
49
# File 'lib/elasticsearch_dsl_builder/dsl/search/queries/geo_bounding_box.rb', line 45

def type(type)
  raise ArgumentError, 'type must be a String' unless type.instance_of?(String)
  @geo_type = type
  self
end