in ts/matchers/contactmatcher.ts [213:235]
private selectMatches(candidates: Speech.Match<Target<Contact>>[]): Contact[] {
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: Contact[] = [];
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.contact);
}
}
}
return matches;
}