85d5e1fe51
- 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
57 lines
1.7 KiB
Rust
57 lines
1.7 KiB
Rust
use anyhow::{Context, Result};
|
|
use momentry_core::core::db::{Database, PostgresDb};
|
|
use momentry_core::core::text::tokenizer::{contains_chinese, tokenize_chinese_text};
|
|
use momentry_core::core::text::{global_synonym_expander, normalize_chinese_query};
|
|
use std::env;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
env::set_var("RUST_LOG", "info");
|
|
|
|
println!("=== 同義詞擴展測試 ===\n");
|
|
|
|
// 初始化 PostgreSQL
|
|
let pg = PostgresDb::init()
|
|
.await
|
|
.context("Failed to initialize PostgreSQL database")?;
|
|
|
|
let expander = global_synonym_expander();
|
|
|
|
// 測試查詢
|
|
let test_queries = vec![
|
|
"電腦",
|
|
"視頻",
|
|
"分析",
|
|
"工作",
|
|
"檔案",
|
|
"電腦工作",
|
|
"工作檔案",
|
|
];
|
|
|
|
for query_str in test_queries {
|
|
println!("\n🔍 測試查詢: '{}'", query_str);
|
|
|
|
// 顯示同義詞擴展
|
|
if contains_chinese(query_str) {
|
|
let normalized = normalize_chinese_query(query_str);
|
|
let expanded = expander.expand_chinese_query(&normalized);
|
|
println!(" 同義詞擴展: {}", expanded);
|
|
}
|
|
|
|
// 顯示轉換後的 tsquery
|
|
match pg.prepare_tsquery(query_str).await {
|
|
Ok(tsquery) => println!(" TSQUERY: {}", tsquery),
|
|
Err(e) => println!(" TSQUERY 錯誤: {}", e),
|
|
}
|
|
|
|
// 執行搜索(即使沒有結果)
|
|
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);
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|