Skip to content

Commit

Permalink
add sort by _geo_distance
Browse files Browse the repository at this point in the history
  • Loading branch information
Keita Suzuki committed Aug 14, 2016
1 parent 34c4c4d commit 6b9ecc2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/searchsort.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ func Sort(field string) *SortDsl {
return &SortDsl{Name: field}
}

func GeoDistanceSort(field interface{}) *SortDsl {
return &SortDsl{GeoDistance: field}
}

type SortBody []interface{}
type SortDsl struct {
Name string
IsDesc bool
Name string
IsDesc bool
GeoDistance interface{}
}

func (s *SortDsl) Desc() *SortDsl {
Expand All @@ -42,6 +47,9 @@ func (s *SortDsl) Asc() *SortDsl {
}

func (s *SortDsl) MarshalJSON() ([]byte, error) {
if s.GeoDistance != nil {
return json.Marshal(map[string]interface{}{"_geo_distance": s.GeoDistance})
}
if s.IsDesc {
return json.Marshal(map[string]string{s.Name: "desc"})
}
Expand Down

0 comments on commit 6b9ecc2

Please sign in to comment.