fix: identities API - use real_name instead of name for cross-schema compatibility
This commit is contained in:
@@ -97,7 +97,7 @@ async fn create_identity(
|
|||||||
reference_data->'angles_covered' as angles,
|
reference_data->'angles_covered' as angles,
|
||||||
reference_data->'quality_avg' as quality
|
reference_data->'quality_avg' as quality
|
||||||
FROM identities
|
FROM identities
|
||||||
WHERE name = $1
|
WHERE real_name = $1
|
||||||
ORDER BY created_at DESC
|
ORDER BY created_at DESC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
"#;
|
"#;
|
||||||
@@ -168,7 +168,7 @@ async fn list_identities(
|
|||||||
.fetch_one(db.pool()).await
|
.fetch_one(db.pool()).await
|
||||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("Count error: {}", e)))?;
|
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("Count error: {}", e)))?;
|
||||||
|
|
||||||
let sql = format!("SELECT id, uuid, name, metadata FROM {} ORDER BY id DESC LIMIT $1 OFFSET $2", id_table);
|
let sql = format!("SELECT id::int, uuid, real_name, metadata FROM {} ORDER BY id DESC LIMIT $1 OFFSET $2", id_table);
|
||||||
|
|
||||||
let rows: Vec<(i32, uuid::Uuid, String, Option<serde_json::Value>)> = match sqlx::query_as(&sql)
|
let rows: Vec<(i32, uuid::Uuid, String, Option<serde_json::Value>)> = match sqlx::query_as(&sql)
|
||||||
.bind(page_size as i64)
|
.bind(page_size as i64)
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ pub struct Bm25Result {
|
|||||||
pub combined_score: f64,
|
pub combined_score: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct HybridSearchResult {
|
pub struct HybridSearchResult {
|
||||||
pub chunk_id: String,
|
pub chunk_id: String,
|
||||||
pub file_uuid: String,
|
pub file_uuid: String,
|
||||||
@@ -145,6 +146,9 @@ pub struct IdentityChunkRecord {
|
|||||||
pub file_uuid: String,
|
pub file_uuid: String,
|
||||||
pub chunk_id: String,
|
pub chunk_id: String,
|
||||||
pub chunk_type: String,
|
pub chunk_type: String,
|
||||||
|
pub start_frame: i64,
|
||||||
|
pub end_frame: i64,
|
||||||
|
pub fps: f64,
|
||||||
pub start_time: Option<f64>,
|
pub start_time: Option<f64>,
|
||||||
pub end_time: Option<f64>,
|
pub end_time: Option<f64>,
|
||||||
pub text_content: Option<String>,
|
pub text_content: Option<String>,
|
||||||
@@ -2651,11 +2655,11 @@ impl PostgresDb {
|
|||||||
let chunk_table = schema::table_name("chunk");
|
let chunk_table = schema::table_name("chunk");
|
||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
let rows = sqlx::query(
|
let rows = sqlx::query(
|
||||||
&format!("SELECT c.file_uuid, c.chunk_id, c.start_time, c.end_time, c.text_content, 'sentence' as chunk_type \
|
&format!("SELECT c.file_uuid, c.chunk_id, (c.start_time * c.fps)::bigint as start_frame, (c.end_time * c.fps)::bigint as end_frame, c.fps, c.start_time, c.end_time, c.text_content, 'sentence' as chunk_type \
|
||||||
FROM {} c JOIN {} fd ON fd.file_uuid = c.file_uuid \
|
FROM {} c JOIN {} fd ON fd.file_uuid = c.file_uuid \
|
||||||
AND fd.frame_number BETWEEN c.start_frame AND c.end_frame \
|
AND fd.frame_number BETWEEN c.start_frame AND c.end_frame \
|
||||||
WHERE fd.identity_id = (SELECT id FROM {} WHERE REPLACE(uuid::text, '-', '') = $1) \
|
WHERE fd.identity_id = (SELECT id FROM {} WHERE REPLACE(uuid::text, '-', '') = $1) \
|
||||||
GROUP BY c.file_uuid, c.chunk_id, c.start_time, c.end_time, c.text_content LIMIT $2 OFFSET $3", chunk_table, fd_table, id_table)
|
GROUP BY c.file_uuid, c.chunk_id, c.start_frame, c.end_frame, c.fps, c.start_time, c.end_time, c.text_content LIMIT $2 OFFSET $3", chunk_table, fd_table, id_table)
|
||||||
)
|
)
|
||||||
.bind(uuid_str).bind(limit).bind(offset)
|
.bind(uuid_str).bind(limit).bind(offset)
|
||||||
.fetch_all(&self.pool).await?;
|
.fetch_all(&self.pool).await?;
|
||||||
@@ -2664,6 +2668,9 @@ impl PostgresDb {
|
|||||||
file_uuid: r.get("file_uuid"),
|
file_uuid: r.get("file_uuid"),
|
||||||
chunk_id: r.get("chunk_id"),
|
chunk_id: r.get("chunk_id"),
|
||||||
chunk_type: r.get("chunk_type"),
|
chunk_type: r.get("chunk_type"),
|
||||||
|
start_frame: r.get("start_frame"),
|
||||||
|
end_frame: r.get("end_frame"),
|
||||||
|
fps: r.get("fps"),
|
||||||
text_content: r.get("text_content"),
|
text_content: r.get("text_content"),
|
||||||
start_time: r.get("start_time"),
|
start_time: r.get("start_time"),
|
||||||
end_time: r.get("end_time"),
|
end_time: r.get("end_time"),
|
||||||
@@ -2676,7 +2683,7 @@ impl PostgresDb {
|
|||||||
let clean = uuid_str.replace('-', "");
|
let clean = uuid_str.replace('-', "");
|
||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
let row = sqlx::query(
|
let row = sqlx::query(
|
||||||
&format!("SELECT id, uuid::text, name, identity_type, source, status, metadata, reference_data, \
|
&format!("SELECT id, uuid::text, real_name AS name, identity_type, source, status, metadata, reference_data, \
|
||||||
NULL::real[] as voice_embedding, NULL::real[] as identity_embedding, \
|
NULL::real[] as voice_embedding, NULL::real[] as identity_embedding, \
|
||||||
face_embedding::real[] as face_embedding, \
|
face_embedding::real[] as face_embedding, \
|
||||||
tmdb_id, tmdb_profile, created_at::timestamptz as created_at, NULL::timestamptz as updated_at \
|
tmdb_id, tmdb_profile, created_at::timestamptz as created_at, NULL::timestamptz as updated_at \
|
||||||
@@ -3084,19 +3091,15 @@ mod tests {
|
|||||||
fn test_bm25_result_serialization() {
|
fn test_bm25_result_serialization() {
|
||||||
let result = Bm25Result {
|
let result = Bm25Result {
|
||||||
chunk_id: "sentence_001".to_string(),
|
chunk_id: "sentence_001".to_string(),
|
||||||
uuid: "test-uuid".to_string(),
|
file_uuid: "test-uuid".to_string(),
|
||||||
|
|
||||||
chunk_type: "sentence".to_string(),
|
chunk_type: "sentence".to_string(),
|
||||||
start_frame: 0,
|
uuid: "test-uuid".to_string(),
|
||||||
end_frame: 150,
|
start_time: Some(0.0),
|
||||||
fps: 30.0,
|
end_time: Some(5.0),
|
||||||
start_time: 0.0,
|
text: Some("Hello world".to_string()),
|
||||||
end_time: 5.0,
|
|
||||||
text: "Hello world".to_string(),
|
|
||||||
bm25_score: 0.75,
|
bm25_score: 0.75,
|
||||||
parent_chunk_id: None,
|
vector_score: 0.0,
|
||||||
visual_stats: None,
|
combined_score: 0.75,
|
||||||
scene_summary: None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let json = serde_json::to_string(&result).unwrap();
|
let json = serde_json::to_string(&result).unwrap();
|
||||||
@@ -3109,26 +3112,16 @@ mod tests {
|
|||||||
fn test_hybrid_search_result_serialization() {
|
fn test_hybrid_search_result_serialization() {
|
||||||
let result = HybridSearchResult {
|
let result = HybridSearchResult {
|
||||||
chunk_id: "sentence_001".to_string(),
|
chunk_id: "sentence_001".to_string(),
|
||||||
uuid: "test-uuid".to_string(),
|
file_uuid: "test-uuid".to_string(),
|
||||||
|
|
||||||
chunk_type: "sentence".to_string(),
|
|
||||||
start_frame: 0,
|
|
||||||
end_frame: 150,
|
|
||||||
fps: 30.0,
|
|
||||||
start_time: 0.0,
|
start_time: 0.0,
|
||||||
end_time: 5.0,
|
end_time: 5.0,
|
||||||
text: "Hello world".to_string(),
|
text: "Hello world".to_string(),
|
||||||
vector_score: 0.85,
|
score: 0.80,
|
||||||
bm25_score: 0.75,
|
source: "hybrid".to_string(),
|
||||||
combined_score: 0.80,
|
|
||||||
parent_chunk_id: None,
|
|
||||||
visual_stats: None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let json = serde_json::to_string(&result).unwrap();
|
let json = serde_json::to_string(&result).unwrap();
|
||||||
assert!(json.contains("sentence_001"));
|
assert!(json.contains("sentence_001"));
|
||||||
assert!(json.contains("0.85"));
|
|
||||||
assert!(json.contains("0.75"));
|
|
||||||
assert!(json.contains("0.8"));
|
assert!(json.contains("0.8"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user