dev: bump to 0.1.66 and harden resolveurl + serienstream
This commit is contained in:
29
addon/search_utils.py
Normal file
29
addon/search_utils.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def normalize_search_text(value: str) -> str:
|
||||
"""Normalisiert Text fuer wortbasierte Suche.
|
||||
|
||||
Gemeinsames Verhalten:
|
||||
- lower-case
|
||||
- Nicht-Alphanumerisches -> Leerzeichen
|
||||
- mehrfachen Whitespace kollabieren
|
||||
"""
|
||||
|
||||
value = (value or "").casefold()
|
||||
value = re.sub(r"[^a-z0-9]+", " ", value)
|
||||
value = re.sub(r"\s+", " ", value).strip()
|
||||
return value
|
||||
|
||||
|
||||
def matches_query(query: str, *, title: str) -> bool:
|
||||
"""True, wenn der normalisierte Titel den normalisierten Query als ganzes Token enthaelt."""
|
||||
|
||||
normalized_query = normalize_search_text(query)
|
||||
if not normalized_query:
|
||||
return False
|
||||
haystack = f" {normalize_search_text(title)} "
|
||||
return f" {normalized_query} " in haystack
|
||||
|
||||
Reference in New Issue
Block a user