mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-19 23:08:08 +02:00
Improve LPR regex support (#19767)
* add regex support to events api for recognized_license_plate * frontend add ability to use regexes in the plate search box and add select all/clear all links to quickly select all filtered plates
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import re
|
||||
import sqlite3
|
||||
|
||||
from playhouse.sqliteq import SqliteQueueDatabase
|
||||
@@ -14,6 +15,10 @@ class SqliteVecQueueDatabase(SqliteQueueDatabase):
|
||||
conn: sqlite3.Connection = super()._connect(*args, **kwargs)
|
||||
if self.load_vec_extension:
|
||||
self._load_vec_extension(conn)
|
||||
|
||||
# register REGEXP support
|
||||
self._register_regexp(conn)
|
||||
|
||||
return conn
|
||||
|
||||
def _load_vec_extension(self, conn: sqlite3.Connection) -> None:
|
||||
@@ -21,6 +26,17 @@ class SqliteVecQueueDatabase(SqliteQueueDatabase):
|
||||
conn.load_extension(self.sqlite_vec_path)
|
||||
conn.enable_load_extension(False)
|
||||
|
||||
def _register_regexp(self, conn: sqlite3.Connection) -> None:
|
||||
def regexp(expr: str, item: str) -> bool:
|
||||
if item is None:
|
||||
return False
|
||||
try:
|
||||
return re.search(expr, item) is not None
|
||||
except re.error:
|
||||
return False
|
||||
|
||||
conn.create_function("REGEXP", 2, regexp)
|
||||
|
||||
def delete_embeddings_thumbnail(self, event_ids: list[str]) -> None:
|
||||
ids = ",".join(["?" for _ in event_ids])
|
||||
self.execute_sql(f"DELETE FROM vec_thumbnails WHERE id IN ({ids})", event_ids)
|
||||
|
||||
Reference in New Issue
Block a user