Spaces:
Sleeping
Sleeping
MichaelEdou Claude Opus 4.6 commited on
Commit ·
67cca0d
1
Parent(s): 6178d50
Fix envelope name matching: use word-level instead of substring matching
Browse filesPrevents false matches where short names are substrings of longer names
(e.g., "Anna" incorrectly matching "Giovanna"). Now every word in the
shorter name must appear as a whole word in the longer name.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
packages/server/src/services/envelopeService.ts
CHANGED
|
@@ -51,11 +51,19 @@ export function lookupEnvelopeNumber(senderName: string): string | null {
|
|
| 51 |
const exact = cache.get(normalizedSender);
|
| 52 |
if (exact) return exact;
|
| 53 |
|
| 54 |
-
// 2.
|
|
|
|
|
|
|
|
|
|
| 55 |
for (const [envName, envNum] of cache) {
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
return envNum;
|
| 60 |
}
|
| 61 |
}
|
|
|
|
| 51 |
const exact = cache.get(normalizedSender);
|
| 52 |
if (exact) return exact;
|
| 53 |
|
| 54 |
+
// 2. Word-level match: every word in the shorter name must appear as a
|
| 55 |
+
// whole word in the longer name. This prevents "Anna" from matching
|
| 56 |
+
// "Giovanna" while still allowing "Jean Dupont" to match
|
| 57 |
+
// "Jean et Marie Dupont".
|
| 58 |
for (const [envName, envNum] of cache) {
|
| 59 |
+
const senderWords = normalizedSender.split(' ');
|
| 60 |
+
const envWords = envName.split(' ');
|
| 61 |
+
// Pick shorter set as the "query" words and the longer set as the pool
|
| 62 |
+
const [query, pool] =
|
| 63 |
+
senderWords.length <= envWords.length
|
| 64 |
+
? [senderWords, envWords]
|
| 65 |
+
: [envWords, senderWords];
|
| 66 |
+
if (query.length > 0 && query.every(w => pool.includes(w))) {
|
| 67 |
return envNum;
|
| 68 |
}
|
| 69 |
}
|