Repository: blakeblackshear/frigate

Issue:
Events Sub_Labels Bug or Improvement
1. If I have so many Sub_Labels that may stretch out of my screen, I need to adjust browser zoom to lower value than 100% so that the drop-down menu appear correctly, otherwise it seems to do nothing when I click it.

2. When for example I want to filter out specific sub-labels (ex: James), anything start with James (ex:JamesBond) will also appear on the list. which I think is not ideal.

3. Sometimes the Sub_Labels contain multiple value, but at the same time some other multiple value is not even on that list which kinda confusing ( see attached image below ). 

4. I think its better to breakdown the Sub_Labels value into single value only, For example when I filter "James" value, the list may contain "James" only, "James" with others or vice versa. 

![Frigate_Sub_Labels_](https://user-images.githubusercontent.com/13220698/221567054-0a457d69-a677-4d9c-ac39-397b3f5e813e.png)



Discussion:
1. Interesting, I'm sure this will affect all types

2 & 3 & 4. Frigate tries to remove all of these multiple values and only show singles, will need to see if I can figure out why it is not happening in this case. 

This is also why James will show any values with James in them. I do not believe there is a way to have the logic include events where there are multiple names but not include where the selected name is a part of the other name. 

For example if you have:
James
JamesBond
James,Nick

there is no good way that I can tell to select James and have it select `James`,`James,Nick` but not `JamesBond`.
Ideally when I select ```James``` it should only show me ```James``` and ```James, Nick```
and the Sub_Labels Drop-down should list 3 entities ```James```, ```Nick```, and ```JamesBond```
> and the Sub_Labels Drop-down should list 3 entities `James`, `Nick`, and `JamesBond`

This is already the case. I am trying to reproduce an issue where it does not split on a `,`  but I am unsuccessful so far

Resolving patch:
diff --git a/frigate/http.py b/frigate/http.py
--- a/frigate/http.py
+++ b/frigate/http.py
@@ -322,7 +322,9 @@ def get_sub_labels():
         sub_labels.remove(None)
 
     if split_joined:
-        for label in sub_labels:
+        original_labels = sub_labels.copy()
+
+        for label in original_labels:
             if "," in label:
                 sub_labels.remove(label)
                 parts = label.split(",")
@@ -331,6 +333,7 @@ def get_sub_labels():
                     if not (part.strip()) in sub_labels:
                         sub_labels.append(part.strip())
 
+    sub_labels.sort()
     return jsonify(sub_labels)
 
 
@@ -638,7 +641,13 @@ def events():
             sub_label_clauses.append((Event.sub_label.is_null()))
 
         for label in filtered_sub_labels:
-            sub_label_clauses.append((Event.sub_label.cast("text") % f"*{label}*"))
+            sub_label_clauses.append(
+                (Event.sub_label.cast("text") == label)
+            )  # include exact matches
+
+            # include this label when part of a list
+            sub_label_clauses.append((Event.sub_label.cast("text") % f"*{label},*"))
+            sub_label_clauses.append((Event.sub_label.cast("text") % f"*, {label}*"))
 
         sub_label_clause = reduce(operator.or_, sub_label_clauses)
         clauses.append((sub_label_clause))


Test patch: