30 lines
520 B
Go
30 lines
520 B
Go
package query
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func MatchNearest(p GeoLocation, entries *[]ISearchable, dist float64, limit int) (*QueryObject, error) {
|
|
|
|
terms := []*QTerm{
|
|
{
|
|
Org: fmt.Sprintf("%f, %f", p.Lat(), p.Lon()),
|
|
Value: "",
|
|
},
|
|
}
|
|
|
|
var locs *GeoLocations
|
|
|
|
locs = GeoLocations(*entries).Clean()
|
|
locs.SortByNearest(p)
|
|
|
|
matches := []ISearchable{}
|
|
for i, loc := range *locs {
|
|
if i < limit {
|
|
matches = append(matches, loc)
|
|
}
|
|
}
|
|
|
|
return &QueryObject{Key: "", Results: &matches, SearchTerms: &terms}, nil
|
|
}
|