From 27b598f1e46ce3ed2eb13af4023817ff7894de38 Mon Sep 17 00:00:00 2001 From: Steve Perkins Date: Wed, 13 Jul 2022 14:24:06 -0400 Subject: [PATCH] handle negative values in ranking field (#3450) really should not have negative values, but trigger counters need to be fixed to avoid bad data in a later commit. --- discovery-provider/src/queries/search_es.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/discovery-provider/src/queries/search_es.py b/discovery-provider/src/queries/search_es.py index 87708473bc9..e9b70808d24 100644 --- a/discovery-provider/src/queries/search_es.py +++ b/discovery-provider/src/queries/search_es.py @@ -365,16 +365,11 @@ def personalize_dsl(dsl, current_user_id, must_saved): def default_function_score(dsl, ranking_field): return { "query": { - "function_score": { + "script_score": { "query": {"bool": dsl}, - "functions": [ - { - "field_value_factor": { - "field": ranking_field, - "modifier": "ln2p", - } - }, - ], + "script": { + "source": f" Math.log(Math.max(doc['{ranking_field}'].value, 0) + 2)" + }, } }, }