Repository navigation
Fix release matching: compare title words whole, ignore accents #1449
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -16,6 +16,16 @@ export function normalizeTitle(title: string): string { | |
| .trim(); | ||
| } | ||
|
|
||
| /** | ||
| * Same as `normalizeTitle`, but accents are stripped first ("Pokémon" -> "pokemon", not | ||
| * "pok mon"), so an accented title matches its plain-ASCII release name. Matching code uses | ||
| * this one. `normalizeTitle` keeps its output because it also builds stored keys (review | ||
| * holds, blacklist entries) that must stay findable after an upgrade. | ||
| */ | ||
| export function normalizeTitleForMatch(title: string): string { | ||
| return normalizeTitle(title.normalize("NFD").replaceAll(/[\u0300-\u036f]/g, "")); | ||
| } | ||
|
|
||
| /** | ||
| * Collapses every run of whitespace (newlines, tabs, repeated spaces) in a release title | ||
| * into a single space and trims it. Some indexer definitions scrape a whole results-table | ||
|
|
@@ -243,8 +253,8 @@ export function isSequelOf(longer: string, shorter: string): boolean { | |
| * Can be used to match a known game title against an xREL title or a cleaned release name. | ||
| */ | ||
| export function titleMatches(a: string, b: string): boolean { | ||
| const normA = normalizeTitle(a); | ||
| const normB = normalizeTitle(b); | ||
| const normA = normalizeTitleForMatch(a); | ||
| const normB = normalizeTitleForMatch(b); | ||
|
|
||
| if (!normA || !normB) return false; | ||
| if (normA === normB) return true; | ||
|
|
@@ -274,11 +284,10 @@ export function releaseMatchesGame(releaseName: string, gameTitle: string): bool | |
| // ("Dishonored.Update.2" would read as "Dishonored 2") and can drop the number itself | ||
| // ("Dishonored-2" looks like a group suffix). Stopword-free forms are checked too, since | ||
| // indexers often drop the "The". | ||
| const normRelease = normalizeTitle(releaseName); | ||
| const normGame = normalizeTitle(gameTitle); | ||
| if ( | ||
| isSequelOf(normRelease, normGame) || | ||
| isSequelOf(withoutStopWords(normRelease), withoutStopWords(normGame)) | ||
| APOSTROPHE_FORMS.some((apostrophes) => | ||
| isSequelRelease(apostrophes(releaseName), apostrophes(gameTitle)) | ||
| ) | ||
| ) { | ||
| return false; | ||
| } | ||
|
|
@@ -289,26 +298,49 @@ export function releaseMatchesGame(releaseName: string, gameTitle: string): bool | |
| // 1. Include numbers (for "Witcher 3" vs "Witcher 2") | ||
| // 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") | ||
| // | ||
| // Releases write "King's" as "Kings" or "King s", so the apostrophe is tried both dropped and | ||
| // spaced, and the sequel guard above runs on each form ("Baldur's.Gate.3" is not "Baldurs Gate"). | ||
| // 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"). Releases that glue the words together ("Left4Dead.2", "SpiderMan") are | ||
| // caught by comparing the title and the release with their spaces removed. | ||
| return APOSTROPHE_FORMS.some((apostrophes) => { | ||
| const gameWords = normalizeTitleForMatch(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; | ||
|
|
||
| const releaseWords = normalizeTitleForMatch(apostrophes(releaseName)).split(" "); | ||
| const releaseWordSet = new Set(releaseWords); | ||
| if (gameWords.every((word) => releaseWordSet.has(word))) return true; | ||
| return releaseWords.join("").includes(gameWords.join("")); | ||
|
Comment on lines
+324
to
+327
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 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)); | ||
| const APOSTROPHE_FORMS: ((text: string) => string)[] = [ | ||
| (t) => t.replaceAll(/['\u2019]/g, ""), | ||
| (t) => t, | ||
| ]; | ||
|
|
||
| /** True when the release reads as a sequel of the game ("Dishonored 2" for "Dishonored"). */ | ||
| function isSequelRelease(releaseName: string, gameTitle: string): boolean { | ||
| const normRelease = normalizeTitleForMatch(releaseName); | ||
| const normGame = normalizeTitleForMatch(gameTitle); | ||
| return ( | ||
| isSequelOf(normRelease, normGame) || | ||
| isSequelOf(withoutStopWords(normRelease), withoutStopWords(normGame)) | ||
| ); | ||
| } | ||
|
|
||
| // 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.
Apply sequel rejection to the representation that compact matching accepts.
releaseMatchesGame("Baldur s Gate 3-GOG", "Baldurs Gate")returnstrue. Neither apostrophe function changes these inputs. The guard cannot find"baldurs gate"in"baldur s gate 3 gog", but compact matching later accepts"baldursgate".Enforce sequel rejection for that recognized title prefix before accepting the compact match. Reject this numbered sequel while preserving
"Baldur s Gate-GOG"as a base-title match. Release-token boundaries alone do not fix this case.