better search term nomralization

This commit is contained in:
Georges-Antoine Assi
2025-07-12 23:52:51 -04:00
parent 72efb1853e
commit c9b09e9ee1
5 changed files with 4 additions and 9 deletions

View File

@@ -52,7 +52,7 @@ class FSPlatformsHandler(FSHandler):
)
try:
platforms = [d for _, d in iter_directories(platforms_dir)]
platforms = sorted([d for _, d in iter_directories(platforms_dir)])
return self._exclude_platforms(cnfg, platforms)
except IndexError as exc:
raise FolderStructureNotMatchException from exc

View File

@@ -56,16 +56,14 @@ COMMA_ARTICLE_PATTERN = re.compile(r",\s(a|an|the)\b$")
NON_WORD_SPACE_PATTERN = re.compile(r"[^\w\s]")
MULTIPLE_SPACE_PATTERN = re.compile(r"\s+")
CHAR_REMOVAL_TABLE = str.maketrans("_'\"", " ")
# This caches results to avoid repeated normalization of the same search term
@lru_cache(maxsize=1024)
def _normalize_search_term(
name: str, remove_articles: bool = True, remove_punctuation: bool = True
) -> str:
# Single translate operation
name = name.lower().translate(CHAR_REMOVAL_TABLE)
# Lower and replace underscores with spaces
name = name.lower().replace("_", " ")
# Remove articles (combined if possible)
if remove_articles:

View File

@@ -572,7 +572,6 @@ class IGDBHandler(MetadataHandler):
if not platform_igdb_id:
return []
search_term = self.normalize_search_term(search_term)
matched_roms = await self._request(
self.games_endpoint,
data=f'search "{uc(search_term)}"; fields {",".join(self.games_fields)}; where platforms=[{platform_igdb_id}];',

View File

@@ -254,10 +254,9 @@ class MobyGamesHandler(MetadataHandler):
if not platform_moby_id:
return []
search_term = uc(search_term)
matched_roms = await self.moby_service.list_games(
platform_ids=[platform_moby_id],
title=quote(search_term, safe="/ "),
title=quote(uc(search_term), safe="/ "),
)
return [

View File

@@ -445,7 +445,6 @@ class SSHandler(MetadataHandler):
if not platform_ss_id:
return []
search_term = self.normalize_search_term(search_term)
matched_roms = await self.ss_service.search_games(
term=quote(uc(search_term), safe="/ "),
system_id=platform_ss_id,