From 67b2b9e2e6e1f1ab3e08b1fea54973459d0029cc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 29 Aug 2024 01:08:44 +0000 Subject: [PATCH] Keep original sorts order (#81) Signed-off-by: David Zane (cherry picked from commit 3c561e0d1a2f64d6ff48c58f0d27528cc9a33a76) Signed-off-by: github-actions[bot] --- .../service/categorizer/QueryShapeGenerator.java | 1 - .../categorizer/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/categorizer/QueryShapeGeneratorTests.java b/src/test/java/org/opensearch/plugin/insights/core/service/categorizer/QueryShapeGeneratorTests.java index 5b4d251a..02264643 100644 --- a/src/test/java/org/opensearch/plugin/insights/core/service/categorizer/QueryShapeGeneratorTests.java +++ b/src/test/java/org/opensearch/plugin/insights/core/service/categorizer/QueryShapeGeneratorTests.java @@ -47,10 +47,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); @@ -82,10 +82,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); } @@ -167,11 +167,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); }