54e6124925
version: sunnypilot v2026.001.000 (dev) date: 2026-05-07T23:07:19 master commit: c28eb958740187620f2282023b8f1997cf90f583
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
"""
|
|
Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors.
|
|
|
|
This file is part of sunnypilot and is licensed under the MIT License.
|
|
See the LICENSE.md file in the root directory for more details.
|
|
"""
|
|
import re
|
|
import unicodedata
|
|
|
|
|
|
def normalize(text: str) -> str:
|
|
return unicodedata.normalize('NFKD', text).encode('ascii', 'ignore').decode('utf-8').lower()
|
|
|
|
|
|
def search_from_list(query: str, items: list[str]) -> list[str]:
|
|
if not query:
|
|
return items
|
|
|
|
normalized_query = normalize(query)
|
|
search_terms = [re.sub(r'[^a-z0-9]', '', term) for term in normalized_query.split() if term.strip()]
|
|
|
|
results = []
|
|
for item in items:
|
|
normalized_item = normalize(item)
|
|
item_with_spaces = re.sub(r'[^a-z0-9\s]', ' ', normalized_item)
|
|
item_stripped = re.sub(r'[^a-z0-9]', '', normalized_item)
|
|
|
|
all_terms_match = True
|
|
for term in search_terms:
|
|
if not term:
|
|
continue
|
|
|
|
if term not in item_with_spaces and term not in item_stripped:
|
|
all_terms_match = False
|
|
break
|
|
|
|
if all_terms_match:
|
|
results.append(item)
|
|
|
|
return results
|