Refactoring codes for more tg message types
This commit is contained in:
29
query/match_locations.go
Normal file
29
query/match_locations.go
Normal file
@@ -0,0 +1,29 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user