From 26f595d8b9fff3b035a7a9d09459fb17e289be21 Mon Sep 17 00:00:00 2001 From: Sam Dornan Date: Mon, 17 Aug 2026 17:01:28 -0500 Subject: [PATCH] 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 --- backend/handler/metadata/hltb_handler.py | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/backend/handler/metadata/hltb_handler.py b/backend/handler/metadata/hltb_handler.py index 74e890764..9a8fb2c66 100644 --- a/backend/handler/metadata/hltb_handler.py +++ b/backend/handler/metadata/hltb_handler.py @@ -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: