The products to scan.
The duplicated identities (empty when every product is unique).
findDuplicateProductIds([{ id: "A" }, { id: "A" }, { id: "B" }]); // ["id:A"]
export function findDuplicateProductIds(results: Product[]): string[] {
const seen = new Set<string>();
const duplicates = new Set<string>();
for (const product of results) {
const key = productIdentity(product);
if (seen.has(key)) {
duplicates.add(key);
} else {
seen.add(key);
}
}
return [...duplicates];
}
Finds product identities that appear more than once, keyed by
productIdentity(ignoring the positional_id). This is detection, not repair: the same product appearing twice means the search almost certainly ran twice, so callers surface it rather than silently removing the duplicates.