mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-27 15:57:07 +03:00
Fix sub label filter for non-ascii names (#24953)
* fix sub label filter for non-ascii names The sub_labels filter lowercased the requested name in Python but the stored value with SQLite's LOWER(), which only folds ASCII. Cyrillic and other non-ASCII names never matched, so filtering by a face name returned no events. Both sides are now lowered in SQLite, which keeps ASCII matching case-insensitive and non-ASCII matching exact. * cover events/search in sub label filter test
This commit is contained in:
+14
-22
@@ -199,18 +199,14 @@ def events(
|
||||
sub_label_clauses.append(Event.sub_label.is_null())
|
||||
|
||||
for label in filtered_sub_labels:
|
||||
lowered = label.lower()
|
||||
sub_label_clauses.append(
|
||||
fn.LOWER(Event.sub_label.cast("text")) == lowered
|
||||
) # include exact matches (case-insensitive)
|
||||
# SQLite LOWER() only folds ASCII, so lower both sides in SQL to
|
||||
# keep non-ASCII names matching exactly
|
||||
stored = fn.LOWER(Event.sub_label.cast("text"))
|
||||
sub_label_clauses.append(stored == fn.LOWER(label))
|
||||
|
||||
# include this label when part of a list (LIKE is case-insensitive in sqlite for ASCII)
|
||||
sub_label_clauses.append(
|
||||
fn.LOWER(Event.sub_label.cast("text")) % f"*{lowered},*"
|
||||
)
|
||||
sub_label_clauses.append(
|
||||
fn.LOWER(Event.sub_label.cast("text")) % f"*, {lowered}*"
|
||||
)
|
||||
# include this label when part of a list
|
||||
sub_label_clauses.append(stored % fn.LOWER(f"*{label},*"))
|
||||
sub_label_clauses.append(stored % fn.LOWER(f"*, {label}*"))
|
||||
|
||||
sub_label_clause = reduce(operator.or_, sub_label_clauses)
|
||||
clauses.append(sub_label_clause)
|
||||
@@ -633,18 +629,14 @@ def events_search(
|
||||
sub_label_clauses.append(Event.sub_label.is_null())
|
||||
|
||||
for label in filtered_sub_labels:
|
||||
lowered = label.lower()
|
||||
sub_label_clauses.append(
|
||||
fn.LOWER(Event.sub_label.cast("text")) == lowered
|
||||
) # include exact matches (case-insensitive)
|
||||
# SQLite LOWER() only folds ASCII, so lower both sides in SQL to
|
||||
# keep non-ASCII names matching exactly
|
||||
stored = fn.LOWER(Event.sub_label.cast("text"))
|
||||
sub_label_clauses.append(stored == fn.LOWER(label))
|
||||
|
||||
# include this label when part of a list (LIKE is case-insensitive in sqlite for ASCII)
|
||||
sub_label_clauses.append(
|
||||
fn.LOWER(Event.sub_label.cast("text")) % f"*{lowered},*"
|
||||
)
|
||||
sub_label_clauses.append(
|
||||
fn.LOWER(Event.sub_label.cast("text")) % f"*, {lowered}*"
|
||||
)
|
||||
# include this label when part of a list
|
||||
sub_label_clauses.append(stored % fn.LOWER(f"*{label},*"))
|
||||
sub_label_clauses.append(stored % fn.LOWER(f"*, {label}*"))
|
||||
|
||||
event_filters.append(reduce(operator.or_, sub_label_clauses))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user