Apache Lucene open-source search software
Fix sorts when grouping
Kevin Risdena414d2468428
diff --git a/solr/core/src/java/org/apache/solr/handler/sql/SolrTable.java b/solr/core/src/java/org/apache/solr/handler/sql/SolrTable.javaindex d937d091f00..167dc95a2e5 100644--- a/solr/core/src/java/org/apache/solr/handler/sql/SolrTable.java+++ b/solr/core/src/java/org/apache/solr/handler/sql/SolrTable.java@@ -94,27 +94,34 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {// List<String> doesn't have add so must make a new ArrayListList<String> fieldsList = new ArrayList<>(fields);+ List<String> orderList = new ArrayList<>(order);- if (order.isEmpty()) {- if(limit != null && Integer.parseInt(limit) > -1) {- solrParams.put(CommonParams.SORT, DEFAULT_SCORE_FIELD + " desc");+ if (!metrics.isEmpty()) {+ for(String bucket : buckets) {+ orderList.add(bucket + " desc");+ }+ }++ if (orderList.isEmpty()) {+ if (limit != null && Integer.parseInt(limit) > -1) {+ orderList.add(DEFAULT_SCORE_FIELD + " desc");// Make sure the default score field is in the field listif (!fieldsList.contains(DEFAULT_SCORE_FIELD)) {fieldsList.add(DEFAULT_SCORE_FIELD);}} else {- solrParams.put(CommonParams.SORT, DEFAULT_VERSION_FIELD + " desc");+ orderList.add(DEFAULT_VERSION_FIELD + " desc");// Make sure the default sort field is in the field listif (!fieldsList.contains(DEFAULT_VERSION_FIELD)) {fieldsList.add(DEFAULT_VERSION_FIELD);}}- } else {- solrParams.put(CommonParams.SORT, String.join(",", order));}+ solrParams.put(CommonParams.SORT, String.join(",", orderList));+if (fieldsList.isEmpty()) {solrParams.put(CommonParams.FL, "*");} else {@@ -124,7 +131,7 @@ class SolrTable extends AbstractQueryableTable implements TranslatableTable {TupleStream tupleStream;String zk = properties.getProperty("zk");try {- if(metrics.isEmpty()) {+ if (metrics.isEmpty()) {if (limit == null) {solrParams.put(CommonParams.QT, "/export");tupleStream = new CloudSolrStream(zk, collection, solrParams);