Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-6156: Fix NullPointerException if group.field grouping is used with rows=0 and timeAllowed (#248)

Christine Poerschke9d33530da1e5
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 262f4dfe132..da261119394 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -433,6 +433,8 @@ Bug Fixes
* SOLR-13209: Fix NPE when no grouping query specified (Collins Abanda via Mike Drob)
+* SOLR-6156: Fix NullPointerException if group.field grouping is used with rows=0 and timeAllowed. (Modassar Ather, Christine Poerschke)
+
Other Changes
---------------------
* SOLR-15566: Clarify ref guide documentation about SQL queries with `SELECT *` requiring a `LIMIT` clause (Timothy Potter)
diff --git a/solr/core/src/java/org/apache/solr/search/grouping/CommandHandler.java b/solr/core/src/java/org/apache/solr/search/grouping/CommandHandler.java
index 7517db1c523..6e25595ef04 100644
--- a/solr/core/src/java/org/apache/solr/search/grouping/CommandHandler.java
+++ b/solr/core/src/java/org/apache/solr/search/grouping/CommandHandler.java
@@ -27,6 +27,8 @@ import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.MultiCollector;
import org.apache.lucene.search.Query;
+import org.apache.lucene.search.ScoreMode;
+import org.apache.lucene.search.SimpleCollector;
import org.apache.lucene.search.TimeLimitingCollector;
import org.apache.lucene.search.TotalHitCountCollector;
import org.apache.lucene.search.grouping.AllGroupHeadsCollector;
@@ -158,7 +160,7 @@ public class CommandHandler {
} else if (!collectors.isEmpty()) {
searchWithTimeLimiter(query, filter, MultiCollector.wrap(collectors.toArray(new Collector[nrOfCommands])));
} else {
- searchWithTimeLimiter(query, filter, null);
+ searchWithTimeLimiter(query, filter, NO_OP_COLLECTOR);
}
for (Command<?> command : commands) {
@@ -166,6 +168,13 @@ public class CommandHandler {
}
}
+ private static Collector NO_OP_COLLECTOR = new SimpleCollector() {
+ @Override
+ public ScoreMode scoreMode() { return ScoreMode.COMPLETE_NO_SCORES; }
+ @Override
+ public void collect(int doc) throws IOException {}
+ };
+
private DocSet computeGroupedDocSet(Query query, ProcessedFilter filter, List<Collector> collectors) throws IOException {
Command<?> firstCommand = commands.get(0);
String field = firstCommand.getKey();
diff --git a/solr/core/src/test/org/apache/solr/TestDistributedGrouping.java b/solr/core/src/test/org/apache/solr/TestDistributedGrouping.java
index 8726e4fe5e1..868a67ccb89 100644
--- a/solr/core/src/test/org/apache/solr/TestDistributedGrouping.java
+++ b/solr/core/src/test/org/apache/solr/TestDistributedGrouping.java
@@ -301,6 +301,14 @@ public class TestDistributedGrouping extends BaseDistributedSearchTestCase {
}
}
+ // SOLR-6156: timeAllowed with rows>0 and rows==0
+ for (String ngroups : new String[] { "false", "true" }) {
+ for (String rows : new String[] { "10", "0" }) {
+ simpleQuery("q", "*:*", "group", "true", "group.field", i1, "group.ngroups", ngroups, "rows", rows);
+ simpleQuery("q", "*:*", "group", "true", "group.field", i1, "group.ngroups", ngroups, "rows", rows, "timeAllowed", "123456");
+ }
+ }
+
ModifiableSolrParams params = new ModifiableSolrParams();
Object[] q = {"q", "*:*", "fq", s1 + ":a", "rows", 1, "fl", "id," + i1, "group", "true", "group.field", i1, "group.limit", -1, "group.ngroups", "true"};