From 25d3e81dfc59dc2a1a7d4541162de919d08fd770 Mon Sep 17 00:00:00 2001 From: tangwang Date: Tue, 11 Nov 2025 21:34:02 +0800 Subject: [PATCH] fix指定sort项时候的bug --- search/searcher.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/search/searcher.py b/search/searcher.py index cb69ae2..ed26657 100644 --- a/search/searcher.py +++ b/search/searcher.py @@ -314,7 +314,7 @@ class Searcher: context.logger.info( f"ES搜索完成 | 耗时: {es_took}ms | " f"命中数: {es_response.get('hits', {}).get('total', {}).get('value', 0)} | " - f"最高分: {es_response.get('hits', {}).get('max_score', 0):.3f}", + f"最高分: {(es_response.get('hits', {}).get('max_score') or 0):.3f}", extra={'reqid': context.reqid, 'uid': context.uid} ) except Exception as e: @@ -339,13 +339,13 @@ class Searcher: result_doc = { '_id': hit['_id'], - '_score': hit['_score'], + '_score': hit.get('_score') or 0.0, '_source': hit['_source'] } # Apply custom ranking if enabled if enable_rerank: - base_score = hit['_score'] + base_score = hit.get('_score') or 0.0 knn_score = None # Check if KNN was used @@ -383,7 +383,7 @@ class Searcher: else: total_value = total - max_score = es_response.get('hits', {}).get('max_score', 0.0) + max_score = es_response.get('hits', {}).get('max_score') or 0.0 # Extract aggregations aggregations = es_response.get('aggregations', {}) @@ -495,7 +495,7 @@ class Searcher: return SearchResult( hits=hits, total=total_value, - max_score=es_response.get('hits', {}).get('max_score', 0.0), + max_score=es_response.get('hits', {}).get('max_score') or 0.0, took_ms=es_response.get('took', 0), query_info={'image_url': image_url, 'search_type': 'image_similarity'} ) -- libgit2 0.21.2