diff --git a/backend/handler/database/roms_handler.py b/backend/handler/database/roms_handler.py index 3ccbd25d8..bbf2b5832 100644 --- a/backend/handler/database/roms_handler.py +++ b/backend/handler/database/roms_handler.py @@ -235,19 +235,18 @@ class DBRomsHandler(DBBaseHandler): return query def _filter_by_search_term(self, query: Query, search_term: str): - search_terms = search_term.split("|") - conditions = [] + terms = [term.strip() for term in search_term.split("|")] + conditions = [ + condition + for term in terms + for condition in ( + Rom.fs_name.ilike(f"%{term}%"), + Rom.name.ilike(f"%{term}%"), + ) + if term + ] - for term in search_terms: - term = term.strip() - if term: # Ensure the term is not empty after stripping - conditions.append(Rom.fs_name.ilike(f"%{term}%")) - conditions.append(Rom.name.ilike(f"%{term}%")) - - if conditions: - return query.filter(or_(*conditions)) - - return query + return query.filter(or_(*conditions)) def _filter_by_matched(self, query: Query, value: bool) -> Query: """Filter based on whether the rom is matched to a metadata provider. diff --git a/backend/tests/handler/test_db_handler.py b/backend/tests/handler/test_db_handler.py index fd0e6be18..b35581f93 100644 --- a/backend/tests/handler/test_db_handler.py +++ b/backend/tests/handler/test_db_handler.py @@ -106,7 +106,6 @@ def test_filter_last_played(rom: Rom, platform: Platform, admin_user: User): def test_filter_by_search_term_with_multiple_terms(platform: Platform): - # Create additional ROMs for testing rom_wwe = db_rom_handler.add_rom( Rom( platform_id=platform.id,