penguin/golifehk

@golifehk bot in Telegram

query/match_locations.go

raw ยท 520 bytes

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
}