private selectMatches()

in ts/matchers/placematcher.ts [188:210]


    private selectMatches(candidates: Speech.Match<Target<Place>>[]): Place[] {
        if (!candidates.length) {
            return [];
        }

        const bestDistance = candidates[0].distance;
        const maxDistance = Math.max(bestDistance * this.config.bestDistanceMultiplier, this.config.maxDistanceMarginReturns);

        const dedupe = new Set<number>([]);
        const matches: Place[] = [];
        for (const candidate of candidates) {
            if (matches.length === this.config.maxReturns) {
                break;
            }
            if (candidate.distance < maxDistance) {
                if (!dedupe.has(candidate.element.id)) {
                    dedupe.add(candidate.element.id);
                    matches.push(candidate.element.place);
                }
            }
        }
        return matches;
    }