Commit 25d3e81dfc59dc2a1a7d4541162de919d08fd770

Authored by tangwang
1 parent c86c8237

fix指定sort项时候的bug

Showing 1 changed file with 5 additions and 5 deletions   Show diff stats
search/searcher.py
@@ -314,7 +314,7 @@ class Searcher: @@ -314,7 +314,7 @@ class Searcher:
314 context.logger.info( 314 context.logger.info(
315 f"ES搜索完成 | 耗时: {es_took}ms | " 315 f"ES搜索完成 | 耗时: {es_took}ms | "
316 f"命中数: {es_response.get('hits', {}).get('total', {}).get('value', 0)} | " 316 f"命中数: {es_response.get('hits', {}).get('total', {}).get('value', 0)} | "
317 - f"最高分: {es_response.get('hits', {}).get('max_score', 0):.3f}", 317 + f"最高分: {(es_response.get('hits', {}).get('max_score') or 0):.3f}",
318 extra={'reqid': context.reqid, 'uid': context.uid} 318 extra={'reqid': context.reqid, 'uid': context.uid}
319 ) 319 )
320 except Exception as e: 320 except Exception as e:
@@ -339,13 +339,13 @@ class Searcher: @@ -339,13 +339,13 @@ class Searcher:
339 339
340 result_doc = { 340 result_doc = {
341 '_id': hit['_id'], 341 '_id': hit['_id'],
342 - '_score': hit['_score'], 342 + '_score': hit.get('_score') or 0.0,
343 '_source': hit['_source'] 343 '_source': hit['_source']
344 } 344 }
345 345
346 # Apply custom ranking if enabled 346 # Apply custom ranking if enabled
347 if enable_rerank: 347 if enable_rerank:
348 - base_score = hit['_score'] 348 + base_score = hit.get('_score') or 0.0
349 knn_score = None 349 knn_score = None
350 350
351 # Check if KNN was used 351 # Check if KNN was used
@@ -383,7 +383,7 @@ class Searcher: @@ -383,7 +383,7 @@ class Searcher:
383 else: 383 else:
384 total_value = total 384 total_value = total
385 385
386 - max_score = es_response.get('hits', {}).get('max_score', 0.0) 386 + max_score = es_response.get('hits', {}).get('max_score') or 0.0
387 387
388 # Extract aggregations 388 # Extract aggregations
389 aggregations = es_response.get('aggregations', {}) 389 aggregations = es_response.get('aggregations', {})
@@ -495,7 +495,7 @@ class Searcher: @@ -495,7 +495,7 @@ class Searcher:
495 return SearchResult( 495 return SearchResult(
496 hits=hits, 496 hits=hits,
497 total=total_value, 497 total=total_value,
498 - max_score=es_response.get('hits', {}).get('max_score', 0.0), 498 + max_score=es_response.get('hits', {}).get('max_score') or 0.0,
499 took_ms=es_response.get('took', 0), 499 took_ms=es_response.get('took', 0),
500 query_info={'image_url': image_url, 'search_type': 'image_similarity'} 500 query_info={'image_url': image_url, 'search_type': 'image_similarity'}
501 ) 501 )