mirror of
https://github.com/rommapp/romm.git
synced 2026-06-28 06:46:00 +00:00
better search term nomralization
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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}];',
|
||||
|
||||
@@ -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 [
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user