0
0
Fork 0

Exposing lon/lat fields in SortGeoDistance struct

This commit is contained in:
Sreekanth Sivasankaran 2017-05-22 11:51:37 +05:30
parent 5c9915c6f4
commit e8374c400b
1 changed files with 9 additions and 9 deletions

View File

@ -67,8 +67,8 @@ func ParseSearchSortObj(input map[string]interface{}) (SearchSort, error) {
rvd := &SortGeoDistance{ rvd := &SortGeoDistance{
Field: field, Field: field,
Desc: descending, Desc: descending,
lon: lon, Lon: lon,
lat: lat, Lat: lat,
unitMult: 1.0, unitMult: 1.0,
} }
if distUnit, ok := input["unit"].(string); ok { if distUnit, ok := input["unit"].(string); ok {
@ -588,8 +588,8 @@ func NewSortGeoDistance(field, unit string, lon, lat float64, desc bool) (
Field: field, Field: field,
Desc: desc, Desc: desc,
Unit: unit, Unit: unit,
lon: lon, Lon: lon,
lat: lat, Lat: lat,
} }
var err error var err error
rv.unitMult, err = geo.ParseDistanceUnit(unit) rv.unitMult, err = geo.ParseDistanceUnit(unit)
@ -608,8 +608,8 @@ type SortGeoDistance struct {
Desc bool Desc bool
Unit string Unit string
values []string values []string
lon float64 Lon float64
lat float64 Lat float64
unitMult float64 unitMult float64
} }
@ -640,7 +640,7 @@ func (s *SortGeoDistance) Value(i *DocumentMatch) string {
docLon := geo.MortonUnhashLon(uint64(i64)) docLon := geo.MortonUnhashLon(uint64(i64))
docLat := geo.MortonUnhashLat(uint64(i64)) docLat := geo.MortonUnhashLat(uint64(i64))
dist := geo.Haversin(s.lon, s.lat, docLon, docLat) dist := geo.Haversin(s.Lon, s.Lat, docLon, docLat)
// dist is returned in km, so convert to m // dist is returned in km, so convert to m
dist *= 1000 dist *= 1000
if s.unitMult != 0 { if s.unitMult != 0 {
@ -690,8 +690,8 @@ func (s *SortGeoDistance) MarshalJSON() ([]byte, error) {
"by": "geo_distance", "by": "geo_distance",
"field": s.Field, "field": s.Field,
"location": map[string]interface{}{ "location": map[string]interface{}{
"lon": s.lon, "lon": s.Lon,
"lat": s.lat, "lat": s.Lat,
}, },
} }
if s.Unit != "" { if s.Unit != "" {