Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-2955: Fixed IllegalStateException when querying with group.sort=score desc in sharded environment.

Martijn van Groningen8a4104be2865
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index b2728b66948..90caa813bed 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -418,6 +418,9 @@ Bug Fixes
* SOLR-2509: StringIndexOutOfBoundsException in the spellchecker collate when the term contains
a hyphen. (Thomas Gambier caught the bug, Steffen Godskesen did the patch, via Erick Erickson)
+
+* SOLR-2955: Fixed IllegalStateException when querying with group.sort=score desc in sharded
+ environment. (Steffen Elberg Godskesen, Martijn van Groningen)
Other Changes
----------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java b/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
index 1b110d237d6..a91f453b370 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
@@ -162,13 +162,18 @@ public class QueryComponent extends SearchComponent
//TODO: move weighting of sort
Sort groupSort = searcher.weightSort(cmd.getSort());
- // groupSort defaults to sort
- String groupSortStr = params.get(GroupParams.GROUP_SORT);
if (groupSort == null) {
- groupSort = new Sort();
+ groupSort = Sort.RELEVANCE;
}
+
+ // groupSort defaults to sort
+ String groupSortStr = params.get(GroupParams.GROUP_SORT);
//TODO: move weighting of sort
Sort sortWithinGroup = groupSortStr == null ? groupSort : searcher.weightSort(QueryParsing.parseSort(groupSortStr, req));
+ if (sortWithinGroup == null) {
+ sortWithinGroup = Sort.RELEVANCE;
+ }
+
groupingSpec.setSortWithinGroup(sortWithinGroup);
groupingSpec.setGroupSort(groupSort);
diff --git a/solr/core/src/test/org/apache/solr/TestDistributedGrouping.java b/solr/core/src/test/org/apache/solr/TestDistributedGrouping.java
index e4b9e9c8a92..c4f61167d57 100755
--- a/solr/core/src/test/org/apache/solr/TestDistributedGrouping.java
+++ b/solr/core/src/test/org/apache/solr/TestDistributedGrouping.java
@@ -140,6 +140,7 @@ public class TestDistributedGrouping extends BaseDistributedSearchTestCase {
query("q", "*:*", "fq", s1 + ":a", "rows", 100, "fl", "id," + i1, "group", "true", "group.field", i1, "group.limit", 10, "sort", i1 + " asc, id asc", "group.truncate", "true", "facet", "true", "facet.field", t1);
// We cannot validate distributed grouping with scoring as first sort. since there is no global idf. We can check if no errors occur
+ simpleQuery("q", "*:*", "rows", 100, "fl", "id," + i1, "group", "true", "group.field", i1, "group.limit", 10, "sort", i1 + " desc", "group.sort", "score desc"); // SOLR-2955
simpleQuery("q", "*:*", "rows", 100, "fl", "id," + i1, "group", "true", "group.field", i1, "group.limit", 10, "sort", "score desc, _docid_ asc, id asc");
simpleQuery("q", "*:*", "rows", 100, "fl", "id," + i1, "group", "true", "group.field", i1, "group.limit", 10);
}
@@ -149,6 +150,7 @@ public class TestDistributedGrouping extends BaseDistributedSearchTestCase {
for (int i = 0; i < queryParams.length; i += 2) {
params.add(queryParams[i].toString(), queryParams[i + 1].toString());
}
+ params.set("shards", shards);
queryServer(params);
}