feat: trace_id i64→i32 fix, OCR search filter, Rule1 OCR trigger

- Fix trace_id SQL type mismatch: i64 → i32 in profile.rs structs and queries
- Add /ocr /asr /asrx search filter suffix to keyword/semantic/smart search
- Fix fetch_ocr_texts to handle both OCR data formats (string array + object array)
- Add has_ocr trigger for Rule1 chunk ingestion in job_worker.rs
- Add search_bm25 chunk_type filter parameter
- Fix single-frame video clip duration (0-frame → 1-frame minimum)
- Re-run Rule1 for 14 files with stuck OCR in pre_chunks
This commit is contained in:
Accusys
2026-07-30 19:34:35 +08:00
parent 5d0c771a2b
commit 85d5e1fe51
20 changed files with 1783 additions and 412 deletions
+39 -26
View File
@@ -1088,6 +1088,17 @@ fn delete_output_files(uuid: &str) -> u64 {
tracing::info!("[UNREGISTER] Deleted workspace SQLite: {}", path.display());
}
}
tracing::info!(
"[UNREGISTER] Deleted {} output files for {}",
deleted_count,
uuid
);
if deleted_count == 0 {
tracing::warn!(
"[UNREGISTER] No output files found to delete for {}",
uuid
);
}
deleted_count
}
@@ -1637,6 +1648,7 @@ async fn sync_file_status(
use crate::core::config::OUTPUT_DIR;
let output_dir = OUTPUT_DIR.as_str();
let videos_table = schema::table_name("videos");
let chunk_table = schema::table_name("chunk");
let tp_table = schema::table_name("trace_profiles");
let tkg_nodes_table = schema::table_name("tkg_nodes");
@@ -1692,12 +1704,9 @@ async fn sync_file_status(
(json_count as i64) == db_count
}
"ocr" => {
let json_count = json_data.get("frames").and_then(|s| s.as_array()).map(|a| a.len()).unwrap_or(0);
let db_count: i64 = sqlx::query_scalar(&format!(
"SELECT COUNT(*) FROM {} WHERE file_uuid = $1 AND processor_type = 'ocr'", pre_table
))
.bind(&file_uuid).fetch_one(state.db.pool()).await.unwrap_or(0);
(json_count as i64) == db_count
// pre_chunks 存的是 grouped chunks (zone + proximity grouping),
// 不等於 frame count,只要 JSON 存在就視為一致
true
}
"cut" => {
let json_count = json_data.get("scenes").and_then(|s| s.as_array()).map(|a| a.len()).unwrap_or(0);
@@ -1708,13 +1717,8 @@ async fn sync_file_status(
(json_count as i64) == db_count
}
"face" => {
let json_frame_count = json_data.get("frames").and_then(|f| f.as_array()).map(|a| a.len()).unwrap_or(0);
let is_no_faces = json_data.get("status").and_then(|s| s.as_str()) == Some("no_faces");
let db_count: i64 = sqlx::query_scalar(&format!(
"SELECT COUNT(*) FROM {} WHERE file_uuid = $1 AND processor_type = 'face'", pre_table
))
.bind(&file_uuid).fetch_one(state.db.pool()).await.unwrap_or(0);
is_no_faces || json_frame_count == (db_count as usize)
// face 已遷移至 Qdrant,不再比對 pre_chunks
true
}
"face_cluster" => {
// cluster 數量可能不等於 trace 數量,只要 JSON 存在就視為一致
@@ -1742,10 +1746,11 @@ async fn sync_file_status(
consistent = false;
}
}
if !consistent {
all_consistent = false;
}
}
// JSON not existing also counts as inconsistent
if !consistent {
all_consistent = false;
}
processor_status.insert(name.to_string(), serde_json::json!({
@@ -1792,24 +1797,32 @@ async fn sync_file_status(
.unwrap_or(None)
.unwrap_or(0) > 0;
// 查詢 processing_status phase
let phase: String = sqlx::query_scalar(&format!(
"SELECT COALESCE(processing_status->>'phase', '') FROM {} WHERE file_uuid = $1",
videos_table
))
.bind(&file_uuid)
.fetch_optional(state.db.pool())
.await
.ok()
.flatten()
.unwrap_or_default();
let phase_completed = phase == "COMPLETED";
// 狀態判斷
let new_status = if all_consistent && any_json_exists {
// 所有 JSON 都存在且與 DB 一致
if has_tkg_edges {
"agent_ready"
} else {
"completed" // 即使 0 筆也算完成
}
"completed"
} else if any_json_exists {
// 部分 JSON 存在但不一致 → 入庫中
// 部分 JSON 存在或不一致 → 入庫中
"scanning"
} else {
// 無 JSON → 未開始
"registered"
};
// 更新 DB status
let videos_table = schema::table_name("videos");
sqlx::query(&format!(
"UPDATE {} SET status = $1, updated_at = NOW() WHERE file_uuid = $2",
videos_table