From fd75a58808d03d0ebc136a9fdb087c7a151db645 Mon Sep 17 00:00:00 2001 From: Martin Gaievski Date: Mon, 18 Nov 2024 13:54:15 -0800 Subject: [PATCH] Assume scode mode from collector Signed-off-by: Martin Gaievski --- .../search/query/QueryCollectorContext.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/server/src/main/java/org/opensearch/search/query/QueryCollectorContext.java b/server/src/main/java/org/opensearch/search/query/QueryCollectorContext.java index dea9668a3706c..32087af75288d 100644 --- a/server/src/main/java/org/opensearch/search/query/QueryCollectorContext.java +++ b/server/src/main/java/org/opensearch/search/query/QueryCollectorContext.java @@ -83,7 +83,8 @@ public ScoreMode scoreMode() { private static final ReduceableSearchResult EMPTY_RESULT = result -> {}; - private static QueryCollectorContext createEmptyContext(String name, Collector collector) { + private static QueryCollectorContext createEmptyContext(Collector collector) { + String name = String.format(Locale.ROOT, "empty_with_score_mode_%s", collector.scoreMode().toString().toLowerCase(Locale.ROOT)); return new QueryCollectorContext(name) { @Override Collector create(Collector in) { @@ -108,19 +109,11 @@ public ReduceableSearchResult reduce(Collection collectors) { }; } - private static String formatContextName(ScoreMode scoreMode) { - return String.format(Locale.ROOT, "empty_with_score_mode_%s", scoreMode.toString().toLowerCase(Locale.ROOT)); - } - private static final Collector EMPTY_COLLECTOR = createEmptyCollector(ScoreMode.COMPLETE_NO_SCORES); - public static final QueryCollectorContext EMPTY_CONTEXT = createEmptyContext( - formatContextName(ScoreMode.COMPLETE_NO_SCORES), - createEmptyCollector(ScoreMode.COMPLETE_NO_SCORES) - ); - public static final QueryCollectorContext EMPTY_CONTEXT_TOP_SCORES_SCORE_MODE = createEmptyContext( - formatContextName(ScoreMode.TOP_SCORES), - createEmptyCollector(ScoreMode.TOP_SCORES) - ); + private static final Collector EMPTY_COLLECTOR_TOP_SCORES = createEmptyCollector(ScoreMode.TOP_SCORES); + + public static final QueryCollectorContext EMPTY_CONTEXT = createEmptyContext(EMPTY_COLLECTOR); + public static final QueryCollectorContext EMPTY_CONTEXT_TOP_SCORES_SCORE_MODE = createEmptyContext(EMPTY_COLLECTOR_TOP_SCORES); private String profilerName;