Class: Queries::GeoDistanceQueryBuilder
- Inherits:
-
QueryBuilder
- Object
- QueryBuilder
- Queries::GeoDistanceQueryBuilder
- Defined in:
- lib/queries/geo_distance_query_builder.rb
Constant Summary collapse
- NAME =
'geo_distance'
- DEFAULT_DISTANCE_UNIT =
::Enums::DistanceUnits.meters
Instance Method Summary collapse
-
#distance(distance, distance_unit = nil) ⇒ Object
Sets distance and distance_unit.
-
#distance_expr ⇒ Object
Returns distance.
-
#distance_type(distance_type) ⇒ Object
Sets distance_type.
-
#distance_type_expr ⇒ Object
Returns distance_type.
-
#distance_unit_expr ⇒ Object
Returns distance_unit.
-
#field_name_expr ⇒ Object
Returns field_name.
-
#ignore_unmapped(ignore_unmapped) ⇒ Object
Sets ignore_unmapped.
-
#ignore_unmapped_expr ⇒ Object
Returns ignore_unmapped.
-
#initialize(field_name:) ⇒ GeoDistanceQueryBuilder
constructor
@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.
-
#point(point) ⇒ Object
Sets point.
-
#point_expr ⇒ Object
Returns point.
- #query ⇒ Object
-
#validation_method(validation_method) ⇒ Object
Sets validation_method.
-
#validation_method_expr ⇒ Object
Returns validation_method.
-
#writable_name(writable_name) ⇒ Object
Sets writable_name.
-
#writable_name_expr ⇒ Object
Returns writable_name.
Methods inherited from QueryBuilder
Methods included from AttributesReader
Methods included from AbstractQueryBuilder
Constructor Details
#initialize(field_name:) ⇒ GeoDistanceQueryBuilder
@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 33 |
# File 'lib/queries/geo_distance_query_builder.rb', line 24 def initialize field_name: @field_name = field_name @point = nil @distance = nil @distance_unit = DEFAULT_DISTANCE_UNIT.distance_unit @distance_type = nil @writable_name = nil @validation_method = nil @ignore_unmapped = nil end |
Instance Method Details
#distance(distance, distance_unit = nil) ⇒ Object
Sets distance and distance_unit
75 76 77 78 79 |
# File 'lib/queries/geo_distance_query_builder.rb', line 75 def distance distance, distance_unit= nil @distance = distance @distance_unit = distance_unit.distance_unit if distance_unit.present? return self end |
#distance_expr ⇒ Object
Returns distance
65 66 67 |
# File 'lib/queries/geo_distance_query_builder.rb', line 65 def distance_expr return @distance end |
#distance_type(distance_type) ⇒ Object
Sets distance_type
87 88 89 90 |
# File 'lib/queries/geo_distance_query_builder.rb', line 87 def distance_type distance_type @distance_type = distance_type.distance_type return self end |
#distance_type_expr ⇒ Object
Returns distance_type
82 83 84 |
# File 'lib/queries/geo_distance_query_builder.rb', line 82 def distance_type_expr return @distance_type end |
#distance_unit_expr ⇒ Object
Returns distance_unit
70 71 72 |
# File 'lib/queries/geo_distance_query_builder.rb', line 70 def distance_unit_expr return @distance_unit end |
#field_name_expr ⇒ Object
Returns field_name
60 61 62 |
# File 'lib/queries/geo_distance_query_builder.rb', line 60 def field_name_expr return @field_name end |
#ignore_unmapped(ignore_unmapped) ⇒ Object
Sets ignore_unmapped
120 121 122 123 |
# File 'lib/queries/geo_distance_query_builder.rb', line 120 def ignore_unmapped ignore_unmapped @ignore_unmapped = ignore_unmapped return self end |
#ignore_unmapped_expr ⇒ Object
Returns ignore_unmapped
115 116 117 |
# File 'lib/queries/geo_distance_query_builder.rb', line 115 def ignore_unmapped_expr return @ignore_unmapped end |
#point(point) ⇒ Object
Sets point
54 55 56 57 |
# File 'lib/queries/geo_distance_query_builder.rb', line 54 def point point @point = point return self end |
#point_expr ⇒ Object
Returns point
49 50 51 |
# File 'lib/queries/geo_distance_query_builder.rb', line 49 def point_expr return @point end |
#query ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/queries/geo_distance_query_builder.rb', line 35 def query query = {} geo_query = self.common_query geo_query[@field_name] = @point.settings geo_query[:distance] = @distance.to_s + @distance_unit.to_s geo_query[:distance_type] = @distance_type 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
109 110 111 112 |
# File 'lib/queries/geo_distance_query_builder.rb', line 109 def validation_method validation_method @validation_method = validation_method.validation_method return self end |
#validation_method_expr ⇒ Object
Returns validation_method
104 105 106 |
# File 'lib/queries/geo_distance_query_builder.rb', line 104 def validation_method_expr return @validation_method end |
#writable_name(writable_name) ⇒ Object
Sets writable_name
98 99 100 101 |
# File 'lib/queries/geo_distance_query_builder.rb', line 98 def writable_name writable_name @writable_name = writable_name return self end |
#writable_name_expr ⇒ Object
Returns writable_name
93 94 95 |
# File 'lib/queries/geo_distance_query_builder.rb', line 93 def writable_name_expr return @writable_name end |