Files
golifehk/query/match_locations.go
2026-03-08 15:38:28 +08:00

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
}