fix: 完成智能服装搜索功能编译错误修复

主要修复:
1. 修复RelevanceThreshold枚举匹配问题,移除不存在的Unspecified变体
2. 修复SearchConfig类型导入问题,使用完整路径引用
3. 修复to_string()调用问题,改用to_owned()
4. 修复未使用变量警告,添加下划线前缀
5. 清理编译缓存,确保所有修改生效

现在应用可以成功编译和启动,智能服装搜索功能已准备好进行测试。
下一步需要测试搜索功能是否能正确调用Vertex AI Search API并返回结果。
This commit is contained in:
imeepos 2025-07-25 13:41:27 +08:00
parent 798b5a2007
commit 0a9e7d4539
1 changed files with 7 additions and 8 deletions

View File

@ -5,7 +5,7 @@ use crate::app_state::AppState;
use crate::data::models::gemini_analysis::{AnalyzeImageRequest, AnalyzeImageResponse}; use crate::data::models::gemini_analysis::{AnalyzeImageRequest, AnalyzeImageResponse};
use crate::data::models::outfit_search::{ use crate::data::models::outfit_search::{
LLMQueryRequest, LLMQueryResponse, OutfitSearchGlobalConfig, ProductInfo, SearchFilterBuilder, LLMQueryRequest, LLMQueryResponse, OutfitSearchGlobalConfig, ProductInfo, SearchFilterBuilder,
SearchRequest, SearchResponse, SearchResult, SearchConfig, SearchRequest, SearchResponse, SearchResult,
}; };
use crate::data::models::outfit_recommendation::{ use crate::data::models::outfit_recommendation::{
OutfitRecommendationRequest, OutfitRecommendationResponse, OutfitRecommendationRequest, OutfitRecommendationResponse,
@ -491,9 +491,8 @@ async fn execute_vertex_ai_search(
crate::data::models::outfit_search::RelevanceThreshold::Low => "LOW", crate::data::models::outfit_search::RelevanceThreshold::Low => "LOW",
crate::data::models::outfit_search::RelevanceThreshold::Medium => "MEDIUM", crate::data::models::outfit_search::RelevanceThreshold::Medium => "MEDIUM",
crate::data::models::outfit_search::RelevanceThreshold::High => "HIGH", crate::data::models::outfit_search::RelevanceThreshold::High => "HIGH",
crate::data::models::outfit_search::RelevanceThreshold::Unspecified => "RELEVANCE_THRESHOLD_UNSPECIFIED",
}; };
payload["relevanceThreshold"] = serde_json::Value::String(threshold_str.to_string()); payload["relevanceThreshold"] = serde_json::Value::String(threshold_str.to_owned());
payload["relevanceScoreSpec"] = serde_json::json!({ payload["relevanceScoreSpec"] = serde_json::json!({
"returnRelevanceScore": true "returnRelevanceScore": true
}); });
@ -655,7 +654,7 @@ async fn get_google_access_token() -> Result<String, anyhow::Error> {
/// 将 Vertex AI Search 响应转换为我们的搜索结果格式 /// 将 Vertex AI Search 响应转换为我们的搜索结果格式
fn convert_vertex_response_to_search_results( fn convert_vertex_response_to_search_results(
vertex_response: &serde_json::Value, vertex_response: &serde_json::Value,
request: &SearchRequest, _request: &SearchRequest,
) -> Result<SearchResponse, anyhow::Error> { ) -> Result<SearchResponse, anyhow::Error> {
let mut results = Vec::new(); let mut results = Vec::new();
@ -670,8 +669,8 @@ fn convert_vertex_response_to_search_results(
search_result.id, search_result.relevance_score search_result.id, search_result.relevance_score
); );
// 应用相关性阈值过滤 // 应用相关性阈值过滤(暂时跳过,直接添加结果)
let threshold = request.config.relevance_threshold.to_value(); // let _threshold = request.config.relevance_threshold;
results.push(search_result); results.push(search_result);
} else { } else {
eprintln!("解析搜索结果失败"); eprintln!("解析搜索结果失败");
@ -901,7 +900,7 @@ pub fn get_outfit_search_command_names() -> Vec<&'static str> {
} }
/// 构建简化的过滤器字符串 - 参考Python实现 /// 构建简化的过滤器字符串 - 参考Python实现
fn build_simple_filters(config: &SearchConfig) -> String { fn build_simple_filters(config: &crate::data::models::outfit_search::SearchConfig) -> String {
let mut filters = Vec::new(); let mut filters = Vec::new();
// 环境标签过滤 // 环境标签过滤
@ -926,7 +925,7 @@ fn build_simple_filters(config: &SearchConfig) -> String {
} }
/// 构建简化的查询字符串 - 参考Python实现 /// 构建简化的查询字符串 - 参考Python实现
fn build_simple_query(base_query: &str, config: &SearchConfig) -> String { fn build_simple_query(base_query: &str, config: &crate::data::models::outfit_search::SearchConfig) -> String {
if !config.query_enhancement_enabled { if !config.query_enhancement_enabled {
return base_query.to_string(); return base_query.to_string();
} }