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:
+28
-68
@@ -1,82 +1,42 @@
|
||||
use anyhow::Result;
|
||||
use momentry_core::core::chunk::rule1_ingest;
|
||||
use momentry_core::core::config;
|
||||
use momentry_core::core::db::PostgresDb;
|
||||
use momentry_core::core::processor::asrx::AsrxResult;
|
||||
use momentry_core::core::processor::face::FaceResult;
|
||||
use momentry_core::core::processor::ocr::OcrResult;
|
||||
use momentry_core::core::processor::pose::PoseResult;
|
||||
use momentry_core::core::processor::yolo::{YoloPythonResult, YoloResult};
|
||||
use momentry_core::worker::processor::ProcessorPool;
|
||||
use serde_json;
|
||||
use std::fs;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
// Initialize tracing
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
// Database connection
|
||||
let db_url = config::DATABASE_URL.clone();
|
||||
let db = PostgresDb::new(&db_url).await?;
|
||||
let db = PostgresDb::new(&config::DATABASE_URL).await?;
|
||||
|
||||
let uuid = "9760d0820f0cf9a7";
|
||||
// Find files with OCR pre_chunks but missing OCR chunks
|
||||
let files: Vec<(String, f64)> = sqlx::query_as::<_, (String, f64)>(
|
||||
r#"
|
||||
SELECT pc.file_uuid, v.fps
|
||||
FROM pre_chunks pc
|
||||
JOIN videos v ON v.file_uuid = pc.file_uuid
|
||||
WHERE pc.processor_type = 'ocr'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM chunk c
|
||||
WHERE c.file_uuid = pc.file_uuid AND c.chunk_type = 'ocr'
|
||||
)
|
||||
GROUP BY pc.file_uuid, v.fps
|
||||
ORDER BY COUNT(*) DESC
|
||||
"#
|
||||
)
|
||||
.fetch_all(db.pool())
|
||||
.await?;
|
||||
|
||||
// Load OCR result
|
||||
let ocr_json =
|
||||
fs::read_to_string("/Users/accusys/momentry/output/job_2_ocr_1774475908877.json")?;
|
||||
let ocr_result: OcrResult = serde_json::from_str(&ocr_json)?;
|
||||
println!("Loaded OCR result with {} frames", ocr_result.frames.len());
|
||||
println!("Found {} files with OCR stuck in pre_chunks", files.len());
|
||||
|
||||
// Load FACE result
|
||||
let face_json =
|
||||
fs::read_to_string("/Users/accusys/momentry/output/job_2_face_1774475908878.json")?;
|
||||
let face_result: FaceResult = serde_json::from_str(&face_json)?;
|
||||
println!(
|
||||
"Loaded FACE result with {} frames",
|
||||
face_result.frames.len()
|
||||
);
|
||||
|
||||
// Load POSE result
|
||||
let pose_json =
|
||||
fs::read_to_string("/Users/accusys/momentry/output/job_2_pose_1774475908880.json")?;
|
||||
let pose_result: PoseResult = serde_json::from_str(&pose_json)?;
|
||||
println!(
|
||||
"Loaded POSE result with {} frames",
|
||||
pose_result.frames.len()
|
||||
);
|
||||
|
||||
// Load ASRX result
|
||||
let asrx_json =
|
||||
fs::read_to_string("/Users/accusys/momentry/output/job_2_asrx_1774475908887.json")?;
|
||||
let asrx_result: AsrxResult = serde_json::from_str(&asrx_json)?;
|
||||
println!(
|
||||
"Loaded ASRX result with {} segments",
|
||||
asrx_result.segments.len()
|
||||
);
|
||||
|
||||
// Load YOLO result
|
||||
let yolo_json =
|
||||
fs::read_to_string("/Users/accusys/momentry/output/job_2_yolo_1774475908875.json")?;
|
||||
let python_result: YoloPythonResult = serde_json::from_str(&yolo_json)?;
|
||||
let yolo_result = python_result.to_yolo_result();
|
||||
println!(
|
||||
"Loaded YOLO result with {} frames",
|
||||
yolo_result.frames.len()
|
||||
);
|
||||
|
||||
// Store chunks using ProcessorPool's static methods
|
||||
println!("Storing OCR chunks...");
|
||||
ProcessorPool::store_ocr_chunks(&db, uuid, &ocr_result).await?;
|
||||
println!("Storing FACE chunks...");
|
||||
ProcessorPool::store_face_chunks(&db, uuid, &face_result).await?;
|
||||
println!("Storing POSE chunks...");
|
||||
ProcessorPool::store_pose_chunks(&db, uuid, &pose_result).await?;
|
||||
println!("Storing ASRX chunks...");
|
||||
ProcessorPool::store_asrx_chunks(&db, uuid, &asrx_result).await?;
|
||||
println!("Storing YOLO chunks...");
|
||||
ProcessorPool::store_yolo_chunks(&db, uuid, &yolo_result).await?;
|
||||
|
||||
println!("All trace chunks stored successfully!");
|
||||
for (file_uuid, fps) in &files {
|
||||
println!("Processing {} (fps={})...", file_uuid, fps);
|
||||
match rule1_ingest::execute_rule1(&db, file_uuid, *fps).await {
|
||||
Ok(count) => println!(" ✅ Created {} chunks", count),
|
||||
Err(e) => eprintln!(" ❌ Failed: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
println!("Done!");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ async fn main() -> Result<()> {
|
||||
Err(e) => println!(" TSQUERY 錯誤: {}", e),
|
||||
}
|
||||
|
||||
let results = pg.search_bm25(query_str, uuid_opt, 5).await?;
|
||||
let results = pg.search_bm25(query_str, uuid_opt, None, 5).await?;
|
||||
|
||||
println!("找到 {} 筆結果:", results.len());
|
||||
for (i, r) in results.iter().enumerate() {
|
||||
|
||||
@@ -26,7 +26,7 @@ async fn main() -> Result<()> {
|
||||
}
|
||||
|
||||
// 執行搜索
|
||||
let results = pg.search_bm25(query_str, None, 5).await?;
|
||||
let results = pg.search_bm25(query_str, None, None, 5).await?;
|
||||
println!(" 找到 {} 筆結果", results.len());
|
||||
for (i, r) in results.iter().enumerate() {
|
||||
println!(" {}. [{}] {}", i + 1, r.uuid, r.text);
|
||||
|
||||
@@ -45,7 +45,7 @@ async fn main() -> Result<()> {
|
||||
}
|
||||
|
||||
// 執行搜索(即使沒有結果)
|
||||
let results = pg.search_bm25(query_str, None, 2).await?;
|
||||
let results = pg.search_bm25(query_str, None, None, 2).await?;
|
||||
println!(" 找到 {} 筆結果", results.len());
|
||||
for (i, r) in results.iter().enumerate() {
|
||||
println!(" {}. [{}] {}", i + 1, r.uuid, r.text);
|
||||
|
||||
Reference in New Issue
Block a user