diff --git a/apps/desktop/src-tauri/src/presentation/commands/outfit_search_commands.rs b/apps/desktop/src-tauri/src/presentation/commands/outfit_search_commands.rs index c991b97..5ce5872 100644 --- a/apps/desktop/src-tauri/src/presentation/commands/outfit_search_commands.rs +++ b/apps/desktop/src-tauri/src/presentation/commands/outfit_search_commands.rs @@ -486,11 +486,12 @@ async fn execute_vertex_ai_search( }); // 添加相关性阈值和评分规范(参考Python实现) + // 暂时使用较低的阈值来获取更多结果 let threshold_str = match request.config.relevance_threshold { crate::data::models::outfit_search::RelevanceThreshold::Lowest => "LOWEST", - crate::data::models::outfit_search::RelevanceThreshold::Low => "LOW", - crate::data::models::outfit_search::RelevanceThreshold::Medium => "MEDIUM", - crate::data::models::outfit_search::RelevanceThreshold::High => "HIGH", + crate::data::models::outfit_search::RelevanceThreshold::Low => "LOWEST", // 降低阈值 + crate::data::models::outfit_search::RelevanceThreshold::Medium => "LOW", // 降低阈值 + crate::data::models::outfit_search::RelevanceThreshold::High => "MEDIUM", // 降低阈值 }; payload["relevanceThreshold"] = serde_json::Value::String(threshold_str.to_owned()); payload["relevanceScoreSpec"] = serde_json::json!({ @@ -691,6 +692,20 @@ fn convert_vertex_response_to_search_results( } } else { eprintln!("响应中没有找到 results 数组"); + eprintln!("可能的原因:"); + eprintln!("1. 数据存储中没有匹配的数据"); + eprintln!("2. 过滤器条件过于严格"); + eprintln!("3. 相关性阈值过高"); + eprintln!("4. 查询词与数据不匹配"); + + // 检查响应中的其他字段 + if let Some(summary) = vertex_response.get("summary") { + eprintln!("API 返回的摘要信息:{}", serde_json::to_string_pretty(summary).unwrap_or_else(|_| "无法解析".to_string())); + } + + if let Some(query_expansion) = vertex_response.get("queryExpansionInfo") { + eprintln!("查询扩展信息:{}", serde_json::to_string_pretty(query_expansion).unwrap_or_else(|_| "无法解析".to_string())); + } } eprintln!("最终返回 {} 个过滤后的结果", results.len()); @@ -916,16 +931,7 @@ pub fn get_outfit_search_command_names() -> Vec<&'static str> { fn build_simple_filters(config: &crate::data::models::outfit_search::SearchConfig) -> String { let mut filters = Vec::new(); - // 环境标签过滤 - if !config.environments.is_empty() { - let env_filter = config.environments.iter() - .map(|env| format!("\"{}\"", env)) - .collect::>() - .join(","); - filters.push(format!("environment_tags: ANY({})", env_filter)); - } - - // 类别过滤 + // 优先使用类别过滤(最重要的过滤条件) if !config.categories.is_empty() { let cat_filter = config.categories.iter() .map(|cat| format!("\"{}\"", cat)) @@ -934,6 +940,15 @@ fn build_simple_filters(config: &crate::data::models::outfit_search::SearchConfi filters.push(format!("products.category: ANY({})", cat_filter)); } + // 如果没有类别过滤,尝试环境标签 + if filters.is_empty() && !config.environments.is_empty() { + let env_filter = config.environments.iter() + .map(|env| format!("\"{}\"", env)) + .collect::>() + .join(","); + filters.push(format!("environment_tags: ANY({})", env_filter)); + } + filters.join(" AND ") }