class Sort::GeoDistanceSortBuilder
Constants
- NAME
Public Class Methods
new(field_name:, point: @field_name = field_name)
click to toggle source
@params:
field_name: The geo point like field the distance based sort operates on. 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). distance_unit: The unit to use when computing sort values. The default is m (meters). nested_sort: Nested path within current object. ignore_unmapped: Indicates if the unmapped field should be treated as a missing value. Setting it to true is equivalent to specifying an unmapped_type in the field sort. The default is false (unmapped field cause the search to fail). point: The point to create the range distance facets from. sort_mode: What to do in case a field has several geo points. By default, the shortest distance is taken into account when sorting in ascending orderand the longest distance when sorting in descending order. Supported values are min, max, median and avg. 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).
# File lib/sort/geo_distance_sort_builder.rb, line 24 def initialize field_name:, point: @field_name = field_name @point = point @distance_type = nil @distance_unit = nil @nested_sort = nil @ignore_unmapped = nil @sort_mode = nil @validation_method = nil end
Public Instance Methods
distance_type(distance_type)
click to toggle source
sets distance_type
# File lib/sort/geo_distance_sort_builder.rb, line 69 def distance_type distance_type @distance_type = distance_type.distance_type return self end
distance_type_expr()
click to toggle source
returns distance_type
# File lib/sort/geo_distance_sort_builder.rb, line 65 def distance_type_expr return @distance_type end
distance_unit(distance_unit)
click to toggle source
sets distance_unit
# File lib/sort/geo_distance_sort_builder.rb, line 79 def distance_unit distance_unit @distance_unit = distance_unit.distance_unit return self end
distance_unit_expr()
click to toggle source
returns distance_unit
# File lib/sort/geo_distance_sort_builder.rb, line 75 def distance_unit_expr return @distance_unit end
field_name_expr()
click to toggle source
returns field_name
# File lib/sort/geo_distance_sort_builder.rb, line 50 def field_name_expr return @field_name end
ignore_unmapped(ignore_unmapped)
click to toggle source
sets ignore_unmapped
# File lib/sort/geo_distance_sort_builder.rb, line 99 def ignore_unmapped ignore_unmapped @ignore_unmapped = ignore_unmapped return self end
ignore_unmapped_expr()
click to toggle source
returns ignore_unmapped
# File lib/sort/geo_distance_sort_builder.rb, line 95 def ignore_unmapped_expr return @ignore_unmapped end
nested_sort(nested_sort)
click to toggle source
sets nested_sort
# File lib/sort/geo_distance_sort_builder.rb, line 89 def nested_sort nested_sort @nested_sort = nested_sort return self end
nested_sort_expr()
click to toggle source
returns nested_sort
# File lib/sort/geo_distance_sort_builder.rb, line 85 def nested_sort_expr return @nested_sort end
point(point)
click to toggle source
sets point
# File lib/sort/geo_distance_sort_builder.rb, line 59 def point point @point = point return self end
point_expr()
click to toggle source
returns point
# File lib/sort/geo_distance_sort_builder.rb, line 55 def point_expr return @point end
query()
click to toggle source
# File lib/sort/geo_distance_sort_builder.rb, line 35 def query query = {} go_query = self.common_query go_query[@field_name.to_s.intern] = @point.settings go_query[:distance_type] = @distance_type if @distance_type.present? go_query[:unit] = @distance_unit if @distance_unit.present? go_query[:nested] = @nested_sort.query if @nested_sort.present? go_query[:ignore_unmapped] = @ignore_unmapped if @ignore_unmapped.present? go_query[:sort_mode] = @sort_mode if @sort_mode.present? go_query[:validation_method] = @validation_method if @validation_method.present? query[name.intern] = go_query return query end
sort_mode(sort_mode)
click to toggle source
sets sort_mode
# File lib/sort/geo_distance_sort_builder.rb, line 109 def sort_mode sort_mode @sort_mode = sort_mode.sort_mode return self end
sort_mode_expr()
click to toggle source
returns sort_mode
# File lib/sort/geo_distance_sort_builder.rb, line 105 def sort_mode_expr return @sort_mode end
validation_method(validation_method)
click to toggle source
# File lib/sort/geo_distance_sort_builder.rb, line 114 def validation_method validation_method @validation_method = validation_method.validation_method return self end