fix(suggestions): even stricter name matching for 2-word names

- For 2-word names: require EXACT same words (no extra words allowed)
- 'Martin Lopez' vs 'Tomas Martin Lopez' → REJECT (different word count)
- 'George Harrison' vs 'Harrison, George' → ACCEPT (same words, different order)
This commit is contained in:
vicrodh committed 2026-02-04 19:41:54 -06:00
1 parent 3a94e250c7
commit 4af2b0b1bd
1 file changed
+12 -10
+12 -10
View File
@@ -468,16 +468,18 @@ fn names_similar(name1: &str, name2: &str) -> bool {
let max_words = words1.len().max(words2.len()); let max_words = words1.len().max(words2.len());
let min_words = words1.len().min(words2.len()); let min_words = words1.len().min(words2.len());
// STRICT: For person names (2-3 words), require ALL words of the shorter name to match // VERY STRICT for person names:
// AND the match ratio must be high (no extra unrelated words) // - For 2-word names: require EXACT same words (handles "George Harrison" vs "Harrison, George")
if min_words <= 3 { // - For 3-word names: allow at most 1 extra word
// All words of shorter name must be in longer name // - This rejects "Martin Lopez" vs "Tomas Martin Lopez" (different people)
let all_short_match = matches == min_words; if min_words == 2 {
// And the longer name shouldn't have too many extra words // For 2-word names, require EXACTLY the same words (just different order allowed)
// e.g., "Martin Mendez" (2) vs "Tomas Martin Lopez" (3) -> 1 match out of 2 = reject // "Martin Lopez" vs "Tomas Martin Lopez" -> max_words=3, min_words=2 -> REJECT
// e.g., "George Harrison" (2) vs "Harrison, George" (2) -> 2 match out of 2 = accept // "George Harrison" vs "Harrison, George" -> max_words=2, min_words=2 -> ACCEPT
let ratio = matches as f32 / max_words as f32; matches == min_words && max_words == min_words
all_short_match && ratio >= 0.66 } else if min_words == 3 {
// For 3-word names, allow at most 1 extra word
matches >= min_words && (max_words - min_words) <= 1
} else { } else {
// For longer names (bands, etc.), allow some flexibility // For longer names (bands, etc.), allow some flexibility
matches as f32 / max_words as f32 >= 0.75 matches as f32 / max_words as f32 >= 0.75