Class: Arelastic::Sorts::GeoDistance

Inherits:
Sort show all
Defined in:
lib/arelastic/sorts/geo_distance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Nodes::Node

#==, #convert_to_elastic, #read_option!

Methods included from Arities::Binary

#binary

Methods included from Arities::Polyadic

#polyadic

Methods included from Arities::Unary

#unary

Constructor Details

#initialize(field, location, options = {}) ⇒ GeoDistance

GeoDistance.new(‘coordinates’, [-70, 40]).as_elastic

=> {'_geo_distance' => {'coordinates' => [-70, 40]}}

GeoDistance.new(‘coordinates’, [-70, 40], ‘distance_type’ => ‘plane’).as_elastic

=> {'_geo_distance' => {'coordinates' => [-70, 40], 'distance_type' => 'plane'}}


12
13
14
15
16
# File 'lib/arelastic/sorts/geo_distance.rb', line 12

def initialize(field, location, options = {})
  @field    = field
  @location = location
  @options  = options
end

Instance Attribute Details

#fieldObject

Returns the value of attribute field.



4
5
6
# File 'lib/arelastic/sorts/geo_distance.rb', line 4

def field
  @field
end

#locationObject

Returns the value of attribute location.



4
5
6
# File 'lib/arelastic/sorts/geo_distance.rb', line 4

def location
  @location
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/arelastic/sorts/geo_distance.rb', line 4

def options
  @options
end

Instance Method Details

#as_elasticObject



18
19
20
# File 'lib/arelastic/sorts/geo_distance.rb', line 18

def as_elastic
  {'_geo_distance' => {field => location}.update(options)}
end