fix(hltb): match titles whose series prefix the catalogue omits

HowLongToBeat is searched with the filename, and a series prefix that one
side carries and the other does not sinks a strict similarity gate: "007:
Quantum of Solace" scores 0.838 against the catalogue's "Quantum of
Solace", just under 0.85, and a term long enough returns no results at
all. Every James Bond title on PlayStation 2 missed for one of those two
reasons.

Retry with the part after the last separator, the same recovery Moby and
ScreenScraper already make. The trigger is broader than theirs, which
only retry an empty result set: a scored-but-rejected result has to
retry too, since that is how "Quantum of Solace" fails.

Verified against the live API: all five PlayStation 2 James Bond titles
now resolve, and six subtitle-heavy titles that could plausibly match the
wrong game on a tail-only search are unaffected, because the full term
matches first.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Sam DornanandClaude Opus 5 committed 2026-08-17 17:01:28 -05:00
1 parent 7f5764660d
commit 26f595d8b9
1 file changed
+27
+27
View File
@@ -527,6 +527,32 @@ class HLTBHandler(MetadataHandler):
search_term = re.sub(DASH_COLON_REGEX, ": ", search_term)
search_term = self.normalize_search_term(search_term, remove_punctuation=False)
return await self._search_and_match(search_term, platform_slug)
async def _search_and_match(self, search_term: str, platform_slug: str) -> HLTBRom:
"""Search HowLongToBeat for one normalized term and score the results.
A series prefix the term carries and the catalogue does not sinks the
similarity score ("007: Quantum of Solace" scores 0.838 against
"Quantum of Solace", under the gate), and a long enough term returns no
results at all, so the part after the last separator is tried as well.
"""
rom = await self._search_and_score(search_term, platform_slug)
if rom["hltb_id"]:
return rom
terms = re.split(self.SEARCH_TERM_SPLIT_PATTERN, search_term)
tail = terms[-1].strip()
if len(terms) > 1 and tail and tail != search_term:
return await self._search_and_score(
tail, platform_slug, split_game_name=True
)
return rom
async def _search_and_score(
self, search_term: str, platform_slug: str, split_game_name: bool = False
) -> HLTBRom:
# Search for games
games = await self.search_games(search_term, platform_slug)
@@ -540,6 +566,7 @@ class HLTBHandler(MetadataHandler):
search_term,
game_names,
min_similarity_score=self.min_similarity_score,
split_game_name=split_game_name,
)
if best_match: