fix: People Search 移除 VLM 文本搜索,只搜索 name 字段
- 移除 search_persons_internal 和 search_people_by_query 中的 VLM 文本搜索 - 避免匹配 'watermark', 'landmark', 'market' 等 VLM 描述文本 - People Search 現在只搜索 tp.name(人物名字) - VLM 相關搜索應使用 Semantic Search API
This commit is contained in:
+19
-43
@@ -215,7 +215,7 @@ pub async fn universal_search(
|
||||
}))
|
||||
}
|
||||
|
||||
/// Search frames by YOLO objects, OCR text, or face IDs
|
||||
/// Search frames by OCR text or face IDs
|
||||
pub async fn search_frames(
|
||||
State(_state): State<crate::api::types::AppState>,
|
||||
Json(req): Json<FrameSearchRequest>,
|
||||
@@ -506,7 +506,7 @@ async fn search_frames_internal(
|
||||
let video_table = "videos";
|
||||
|
||||
let mut sql = format!(
|
||||
"SELECT f.frame_number, f.timestamp, f.yolo_objects, f.ocr_results, f.face_results, v.file_uuid
|
||||
"SELECT f.frame_number, f.timestamp, f.ocr_results, f.face_results, v.file_uuid
|
||||
FROM {} f JOIN {} v ON f.file_id = v.id WHERE 1=1",
|
||||
table, video_table
|
||||
);
|
||||
@@ -522,9 +522,8 @@ async fn search_frames_internal(
|
||||
}
|
||||
if let Some(ref filters) = req.filters {
|
||||
if let Some(ref classes) = filters.object_class {
|
||||
for class in classes {
|
||||
sql.push_str(&format!(" AND f.yolo_objects::text ILIKE '%{}%'", class));
|
||||
}
|
||||
// Object class filter removed (YOLO disabled)
|
||||
tracing::warn!("object_class filter ignored: YOLO processor removed");
|
||||
}
|
||||
if let Some(ref ocr) = filters.ocr_text {
|
||||
sql.push_str(&format!(" AND f.ocr_results::text ILIKE '%{}%'", ocr));
|
||||
@@ -539,10 +538,10 @@ async fn search_frames_internal(
|
||||
}
|
||||
}
|
||||
if !req.query.is_empty() {
|
||||
// Search across all frame data
|
||||
// Search across frame data (OCR and face results)
|
||||
sql.push_str(&format!(
|
||||
" AND (f.yolo_objects::text ILIKE '%{}%' OR f.ocr_results::text ILIKE '%{}%' OR f.face_results::text ILIKE '%{}%')",
|
||||
req.query, req.query, req.query
|
||||
" AND (f.ocr_results::text ILIKE '%{}%' OR f.face_results::text ILIKE '%{}%')",
|
||||
req.query, req.query
|
||||
));
|
||||
}
|
||||
|
||||
@@ -554,17 +553,13 @@ async fn search_frames_internal(
|
||||
f64,
|
||||
Option<serde_json::Value>,
|
||||
Option<serde_json::Value>,
|
||||
Option<serde_json::Value>,
|
||||
String,
|
||||
)> = sqlx::query_as(&sql).fetch_all(db.pool()).await?;
|
||||
|
||||
let results: Vec<SearchResult> = rows
|
||||
.into_iter()
|
||||
.map(|(frame_number, timestamp, yolo, ocr, face, file_uuid)| {
|
||||
let objects = yolo.as_ref().and_then(|v| {
|
||||
v.get("objects")
|
||||
.map(|o| o.as_array().cloned().unwrap_or_default())
|
||||
});
|
||||
.map(|(frame_number, timestamp, ocr, face, file_uuid)| {
|
||||
let objects: Vec<serde_json::Value> = vec![];
|
||||
let ocr_texts = ocr.as_ref().and_then(|v| {
|
||||
v.get("texts").and_then(|t| {
|
||||
t.as_array().map(|arr| {
|
||||
@@ -586,7 +581,7 @@ async fn search_frames_internal(
|
||||
frame_number,
|
||||
timestamp,
|
||||
score: 0.7,
|
||||
objects: objects.map(|arr| arr.iter().map(|v| v.clone()).collect()),
|
||||
objects: None,
|
||||
ocr_texts,
|
||||
faces,
|
||||
pose_persons: None,
|
||||
@@ -619,15 +614,7 @@ async fn search_persons_internal(
|
||||
);
|
||||
if !req.query.is_empty() {
|
||||
let q = req.query.replace('\'', "''");
|
||||
sql.push_str(&format!(
|
||||
" AND (tp.name ILIKE '%{0}%' \
|
||||
OR tp.vlm_description ILIKE '%{0}%' \
|
||||
OR tp.vlm_clothing ILIKE '%{0}%' \
|
||||
OR EXISTS (SELECT 1 FROM unnest(tp.vlm_tags) tag WHERE tag ILIKE '%{0}%') \
|
||||
OR tp.vlm_location ILIKE '%{0}%' \
|
||||
OR tp.vlm_setting ILIKE '%{0}%')",
|
||||
q
|
||||
));
|
||||
sql.push_str(&format!(" AND tp.name ILIKE '%{0}%'", q));
|
||||
}
|
||||
if let Some(ref fuuid) = req.file_uuid {
|
||||
let safe = fuuid.replace('\'', "''");
|
||||
@@ -704,7 +691,7 @@ async fn search_frames_internal_v2(
|
||||
let video_table = "videos";
|
||||
|
||||
let mut sql = format!(
|
||||
"SELECT f.frame_number, f.timestamp, f.yolo_objects, f.ocr_results, f.face_results, v.file_uuid
|
||||
"SELECT f.frame_number, f.timestamp, f.ocr_results, f.face_results, v.file_uuid
|
||||
FROM {} f JOIN {} v ON f.file_id = v.id WHERE 1=1",
|
||||
table, video_table
|
||||
);
|
||||
@@ -718,8 +705,9 @@ async fn search_frames_internal_v2(
|
||||
tr[0], tr[1]
|
||||
));
|
||||
}
|
||||
if let Some(ref class) = req.object_class {
|
||||
sql.push_str(&format!(" AND f.yolo_objects::text ILIKE '%{}%'", class));
|
||||
if let Some(ref _class) = req.object_class {
|
||||
// Object class filter removed (YOLO disabled)
|
||||
tracing::warn!("object_class filter ignored: YOLO processor removed");
|
||||
}
|
||||
if let Some(ref ocr) = req.ocr_text {
|
||||
sql.push_str(&format!(" AND f.ocr_results::text ILIKE '%{}%'", ocr));
|
||||
@@ -736,17 +724,13 @@ async fn search_frames_internal_v2(
|
||||
f64,
|
||||
Option<serde_json::Value>,
|
||||
Option<serde_json::Value>,
|
||||
Option<serde_json::Value>,
|
||||
String,
|
||||
)> = sqlx::query_as(&sql).fetch_all(db.pool()).await?;
|
||||
|
||||
let results: Vec<FrameResult> = rows
|
||||
.into_iter()
|
||||
.map(|(frame_number, timestamp, yolo, ocr, face, uuid)| {
|
||||
let objects = yolo.as_ref().and_then(|v| {
|
||||
v.get("objects")
|
||||
.map(|o| o.as_array().cloned().unwrap_or_default())
|
||||
});
|
||||
.map(|(frame_number, timestamp, ocr, face, uuid)| {
|
||||
let objects: Option<Vec<serde_json::Value>> = None;
|
||||
let ocr_texts = ocr.as_ref().and_then(|v| {
|
||||
v.get("texts").and_then(|t| {
|
||||
t.as_array().map(|arr| {
|
||||
@@ -766,7 +750,7 @@ async fn search_frames_internal_v2(
|
||||
frame_number,
|
||||
timestamp,
|
||||
file_uuid: uuid,
|
||||
objects: objects.map(|arr| arr.iter().map(|v| v.clone()).collect()),
|
||||
objects: None,
|
||||
ocr_texts,
|
||||
faces,
|
||||
pose_persons: None,
|
||||
@@ -802,15 +786,7 @@ async fn search_people_by_query(
|
||||
);
|
||||
if let Some(q) = query {
|
||||
let safe = q.replace('\'', "''");
|
||||
sql.push_str(&format!(
|
||||
" AND (tp.name ILIKE '%{0}%' \
|
||||
OR tp.vlm_description ILIKE '%{0}%' \
|
||||
OR tp.vlm_clothing ILIKE '%{0}%' \
|
||||
OR EXISTS (SELECT 1 FROM unnest(tp.vlm_tags) tag WHERE tag ILIKE '%{0}%') \
|
||||
OR tp.vlm_location ILIKE '%{0}%' \
|
||||
OR tp.vlm_setting ILIKE '%{0}%')",
|
||||
safe
|
||||
));
|
||||
sql.push_str(&format!(" AND tp.name ILIKE '%{0}%'", safe));
|
||||
}
|
||||
if let Some(fuuid) = file_uuid {
|
||||
let safe = fuuid.replace('\'', "''");
|
||||
|
||||
Reference in New Issue
Block a user