From 555b060f2bebf587cb8e0bddcc0ab62b157e650e Mon Sep 17 00:00:00 2001 From: David Zane Date: Wed, 28 Aug 2024 17:03:10 -0700 Subject: [PATCH] Keep original sorts order Signed-off-by: David Zane --- .../service/categorizer/QueryShapeGenerator.java | 1 - .../categorizor/QueryShapeGeneratorTests.java | 16 ++++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/opensearch/plugin/insights/core/service/categorizer/QueryShapeGenerator.java b/src/main/java/org/opensearch/plugin/insights/core/service/categorizer/QueryShapeGenerator.java index f3db022a..aedc6340 100644 --- a/src/main/java/org/opensearch/plugin/insights/core/service/categorizer/QueryShapeGenerator.java +++ b/src/main/java/org/opensearch/plugin/insights/core/service/categorizer/QueryShapeGenerator.java @@ -226,7 +226,6 @@ static String buildSortShape(List> sortBuilderList, Boolean showF shapeStrings.add(stringBuilder.toString()); } - Collections.sort(shapeStrings); for (String line : shapeStrings) { sortShape.append(line).append("\n"); } diff --git a/src/test/java/org/opensearch/plugin/insights/core/service/categorizor/QueryShapeGeneratorTests.java b/src/test/java/org/opensearch/plugin/insights/core/service/categorizor/QueryShapeGeneratorTests.java index 5e04fa9f..8db2d89d 100644 --- a/src/test/java/org/opensearch/plugin/insights/core/service/categorizor/QueryShapeGeneratorTests.java +++ b/src/test/java/org/opensearch/plugin/insights/core/service/categorizor/QueryShapeGeneratorTests.java @@ -48,10 +48,10 @@ public void testComplexSearch() { + " derivative\n" + " max_bucket\n" + "sort:\n" - + " asc [album]\n" - + " asc [price]\n" + " desc [color]\n" - + " desc [vendor]\n"; + + " desc [vendor]\n" + + " asc [price]\n" + + " asc [album]\n"; assertEquals(expectedShowFieldsTrue, shapeShowFieldsTrue); String shapeShowFieldsFalse = QueryShapeGenerator.buildShape(sourceBuilder, false); @@ -83,10 +83,10 @@ public void testComplexSearch() { + " derivative\n" + " max_bucket\n" + "sort:\n" - + " asc\n" - + " asc\n" + " desc\n" - + " desc\n"; + + " desc\n" + + " asc\n" + + " asc\n"; assertEquals(expectedShowFieldsFalse, shapeShowFieldsFalse); } @@ -168,11 +168,11 @@ public void testSortShape() { SearchSourceBuilder sourceBuilder = SearchSourceBuilderUtils.createSortSearchSourceBuilder(); String shapeShowFieldsTrue = QueryShapeGenerator.buildShape(sourceBuilder, true); - String expectedShowFieldsTrue = "sort:\n" + " asc [album]\n" + " asc [price]\n" + " desc [color]\n" + " desc [vendor]\n"; + String expectedShowFieldsTrue = "sort:\n" + " desc [color]\n" + " desc [vendor]\n" + " asc [price]\n" + " asc [album]\n"; assertEquals(expectedShowFieldsTrue, shapeShowFieldsTrue); String shapeShowFieldsFalse = QueryShapeGenerator.buildShape(sourceBuilder, false); - String expectedShowFieldsFalse = "sort:\n" + " asc\n" + " asc\n" + " desc\n" + " desc\n"; + String expectedShowFieldsFalse = "sort:\n" + " desc\n" + " desc\n" + " asc\n" + " asc\n"; assertEquals(expectedShowFieldsFalse, shapeShowFieldsFalse); }