31 lines
590 B
Go
31 lines
590 B
Go
package query
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func MatchNearest(p IGeoLocation, 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, item := range *locs {
|
|
loc := item.(IGeoLocation)
|
|
if i < limit && loc.Dist(p.Lat(), p.Lon()) <= dist {
|
|
matches = append(matches, item)
|
|
}
|
|
}
|
|
|
|
return &QueryObject{Key: "", Results: &matches, SearchTerms: &terms}, nil
|
|
}
|