Exposing lon/lat fields in SortGeoDistance struct
This commit is contained in:
parent
5c9915c6f4
commit
e8374c400b
|
@ -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 != "" {
|
||||||
|
|
Loading…
Reference in New Issue