Repository navigation
Fix release matching: compare title words whole, ignore accents #1349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ | |
| */ | ||
| export function normalizeTitle(title: string): string { | ||
| return title | ||
| .normalize("NFD") | ||
| .replaceAll(/[\u0300-\u036f]/g, "") // "Pokémon" -> "Pokemon", not "pok mon" | ||
| .toLowerCase() | ||
| .replaceAll(/[^a-z0-9\s]/g, " ") // Replace non-alphanumeric with space | ||
| .replaceAll(/\s+/g, " ") // Multiple spaces to single space | ||
|
|
@@ -288,25 +290,29 @@ export function releaseMatchesGame(releaseName: string, gameTitle: string): bool | |
| // 2. Filter common stopwords | ||
| // 3. Require at least one "meaningful" word (> 2 chars or specific) to avoid matching "Stalker 2" against "Witcher 2" (via "2") | ||
|
|
||
| const gameWords = normalizeTitle(gameTitle) | ||
| .split(" ") | ||
| .filter((w) => { | ||
| // Keep if it's a number (length 1 allowed) OR length > 1 | ||
| if (w.length < 2 && isNaN(Number(w))) return false; | ||
| // Filter stopwords | ||
| if (TITLE_STOP_WORDS.has(w)) return false; | ||
| return true; | ||
| }); | ||
|
|
||
| // Calculate meaningful words (longer than 2 chars) | ||
| // If we have NO meaningful words (e.g. "Stalker 2" -> ["2"] where stalker is lost due to spaces, or "It"), | ||
| // disable fallback to prevent false positives. | ||
| const meaningfulWords = gameWords.filter((w) => w.length > 2); | ||
|
|
||
| if (meaningfulWords.length === 0) return false; | ||
|
|
||
| const normalizedRelease = releaseName.toLowerCase().replace(/[._-]/g, " "); | ||
| return gameWords.every((word) => normalizedRelease.includes(word)); | ||
| // Releases write "King's" as "Kings" or "King s", so try the apostrophe both dropped and | ||
| // spaced. Words must match whole: a substring check let "1-2-Switch" match "Super Mario | ||
| // Galaxy 2 (v1.2.0) [Switch]" ("1" inside "v1") and "Luigi's Mansion 3" match "Luigi 039s | ||
| // Mansion 2 HD" ("3" inside "039s"). | ||
| return [(t: string) => t.replaceAll(/['\u2019]/g, ""), (t: string) => t].some((apostrophes) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apply sequel protection to the apostrophe variants. For Run the sequel checks against the same apostrophe variants before accepting a fallback match. Add this case as a regression test.
|
||
| const gameWords = normalizeTitle(apostrophes(gameTitle)) | ||
| .split(" ") | ||
| .filter((w) => { | ||
| // Keep if it's a number (length 1 allowed) OR length > 1 | ||
| if (w.length < 2 && isNaN(Number(w))) return false; | ||
| // Filter stopwords | ||
| if (TITLE_STOP_WORDS.has(w)) return false; | ||
| return true; | ||
| }); | ||
|
|
||
| // Calculate meaningful words (longer than 2 chars) | ||
| // If we have NO meaningful words (e.g. "Stalker 2" -> ["2"] where stalker is lost due to spaces, or "It"), | ||
| // disable fallback to prevent false positives. | ||
| if (!gameWords.some((w) => w.length > 2)) return false; | ||
|
Comment on lines
+297
to
+311
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| const releaseWords = new Set(normalizeTitle(apostrophes(releaseName)).split(" ")); | ||
| return gameWords.every((word) => releaseWords.has(word)); | ||
| }); | ||
| } | ||
|
|
||
| // Trailing edition words an indexer rarely carries in the release name ("... Game of the Year | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep existing auto-download holds matchable after the key change.
The new
normalizeTitlechanges the hold key for accented titles.pokemon swordreplacespok mon sword.cron.tslooks up holds with the new key, andDatabaseStorage.hasAiAutoDownloadHoldcomparesrelease_titleexactly. No migration rewrites existing keys, and the lookup does not accept the old form.An unexpired hold created before this change is therefore not found. The release is re-analyzed. If the AI check returns a hold reason, the release is held again, and a second review notification is recorded because the new key does not conflict with the old row. If the check returns no reason, the release downloads without the review the hold was meant to enforce. Manual clearing through
routes.tsalso misses old-key rows.Choose a compatibility path before merge. Either migrate existing
release_titlevalues to the new key, or make lookup and clear accept both the old and new keys. A migration must handle collisions on the(game_id, release_title)unique index.