Class: Queries::GeoBoundingBoxQueryBuilder

Inherits:
QueryBuilder show all
Defined in:
lib/queries/geo_bounding_box_query_builder.rb

Constant Summary collapse

NAME =
'geo_bounding_box'
DEFAULT_DISTANCE_UNIT =
::Enums::DistanceUnits.meters

Instance Method Summary collapse

Methods inherited from QueryBuilder

#boost

Methods included from AttributesReader

#attributes

Methods included from AbstractQueryBuilder

#do_equals?, #name

Constructor Details

#initialize(field_name:) ⇒ GeoBoundingBoxQueryBuilder

@params:

field_name: geo_point field in the document which is matched with the given query
point: center point for this query
distance: The radius of the circle centred on the specified location. Points which fall into this circle are considered to be matches.
distance_unit: The distance can be specified in various units. See Distance Units.
distance_type: How to compute the distance. Can either be arc (default),
               or plane (faster, but inaccurate on long distances and close to the poles)
writable_name: Optional name field to identify the query
validation_method: Set to IGNORE_MALFORMED to accept geo points with invalid latitude or longitude,
                   set to COERCE to additionally try and infer correct coordinates (default is STRICT).
ignore_unmapped: When set to true the ignore_unmapped option will ignore an unmapped field and will not match any documents for this query.
                 When set to false (the default value) the query will throw an exception if the field is not mapped.


24
25
26
27
28
29
30
31
32
# File 'lib/queries/geo_bounding_box_query_builder.rb', line 24

def initialize field_name:
  @field_name = field_name
  @point = nil
  @distance = nil
  @distance_unit = DEFAULT_DISTANCE_UNIT.distance_unit
  @writable_name = nil
  @validation_method = nil
  @ignore_unmapped = nil
end

Instance Method Details

#distance(distance, distance_unit = nil) ⇒ Object

Sets distance and distance_unit



72
73
74
75
76
# File 'lib/queries/geo_bounding_box_query_builder.rb', line 72

def distance distance, distance_unit= nil
  @distance = distance
  @distance_unit = distance_unit.distance_unit if distance_unit.present?
  return self
end

#distance_exprObject

Returns distance



62
63
64
# File 'lib/queries/geo_bounding_box_query_builder.rb', line 62

def distance_expr
  return @distance
end

#distance_type(distance_type) ⇒ Object

Sets distance_type



84
85
86
87
# File 'lib/queries/geo_bounding_box_query_builder.rb', line 84

def distance_type distance_type
  @distance_type = distance_type.distance_type
  return self
end

#distance_type_exprObject

Returns distance_type



79
80
81
# File 'lib/queries/geo_bounding_box_query_builder.rb', line 79

def distance_type_expr
  return @distance_type
end

#distance_unit_exprObject

Returns distance_unit



67
68
69
# File 'lib/queries/geo_bounding_box_query_builder.rb', line 67

def distance_unit_expr
  return @distance_unit
end

#field_name_exprObject

Returns field_name



57
58
59
# File 'lib/queries/geo_bounding_box_query_builder.rb', line 57

def field_name_expr
  return @field_name
end

#ignore_unmapped(ignore_unmapped) ⇒ Object

Sets ignore_unmapped



117
118
119
120
# File 'lib/queries/geo_bounding_box_query_builder.rb', line 117

def ignore_unmapped ignore_unmapped
  @ignore_unmapped = ignore_unmapped
  return self
end

#ignore_unmapped_exprObject

Returns ignore_unmapped



112
113
114
# File 'lib/queries/geo_bounding_box_query_builder.rb', line 112

def ignore_unmapped_expr
  return @ignore_unmapped
end

#point(point) ⇒ Object

Sets point



51
52
53
54
# File 'lib/queries/geo_bounding_box_query_builder.rb', line 51

def point point
  @point = point
  return self
end

#point_exprObject

Returns point



46
47
48
# File 'lib/queries/geo_bounding_box_query_builder.rb', line 46

def point_expr
  return @point
end

#queryObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/queries/geo_bounding_box_query_builder.rb', line 34

def query
  query = {}
  geo_query = self.common_query
  geo_query[@field_name] = @point.settings
  geo_query[:writable_name] = @writable_name
  geo_query[:validation_method] = @validation_method
  geo_query[:ignore_unmapped] = @ignore_unmapped
  query[name.intern] = geo_query
  return query
end

#validation_method(validation_method) ⇒ Object

Sets validation_method



106
107
108
109
# File 'lib/queries/geo_bounding_box_query_builder.rb', line 106

def validation_method validation_method
  @validation_method = validation_method.validation_method
  return self
end

#validation_method_exprObject

Returns validation_method



101
102
103
# File 'lib/queries/geo_bounding_box_query_builder.rb', line 101

def validation_method_expr
  return @validation_method
end

#writable_name(writable_name) ⇒ Object

Sets writable_name



95
96
97
98
# File 'lib/queries/geo_bounding_box_query_builder.rb', line 95

def writable_name writable_name
  @writable_name = writable_name
  return self
end

#writable_name_exprObject

Returns writable_name



90
91
92
# File 'lib/queries/geo_bounding_box_query_builder.rb', line 90

def writable_name_expr
  return @writable_name
end