You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sa...@apache.org on 2016/12/06 23:13:31 UTC
[36/50] [abbrv] lucene-solr:apiv2: SOLR-9616 Solr throws exception
when expand=true on empty index
SOLR-9616 Solr throws exception when expand=true on empty index
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/e64bcb37
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/e64bcb37
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/e64bcb37
Branch: refs/heads/apiv2
Commit: e64bcb37ffe9ccbe1c88cb451ff147de774aec8e
Parents: 9eaea79
Author: Ishan Chattopadhyaya <ic...@gmail.com>
Authored: Thu Dec 1 00:46:58 2016 +0530
Committer: Ishan Chattopadhyaya <ic...@gmail.com>
Committed: Thu Dec 1 00:46:58 2016 +0530
----------------------------------------------------------------------
solr/CHANGES.txt | 2 ++
.../solr/handler/component/ExpandComponent.java | 6 ++++++
.../solr/handler/component/TestExpandComponent.java | 15 +++++++++++++++
3 files changed, 23 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e64bcb37/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 1584647..d09ae3b 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -218,6 +218,8 @@ Bug Fixes
* SOLR-9768: RecordingJsonParser produces incomplete json (Wojciech Stryszyk via ab)
+* SOLR-9616: Solr throws exception when expand=true on empty index (Timo Hund via Ishan Chattopadhyaya)
+
Other Changes
----------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e64bcb37/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java b/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
index 8274d68..366c4a9 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
@@ -265,6 +265,12 @@ public class ExpandComponent extends SearchComponent implements PluginInfoInitia
* This code gathers the group information for the current page.
*/
List<LeafReaderContext> contexts = searcher.getTopReaderContext().leaves();
+
+ if(contexts.size() == 0) {
+ //When no context is available we can skip the expanding
+ return;
+ }
+
int currentContext = 0;
int currentDocBase = contexts.get(currentContext).docBase;
int nextDocBase = (currentContext+1)<contexts.size() ? contexts.get(currentContext+1).docBase : Integer.MAX_VALUE;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e64bcb37/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java b/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java
index 7d38d62..f7fc13a 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java
@@ -314,4 +314,19 @@ public class TestExpandComponent extends SolrTestCaseJ4 {
);
}
+ @Test
+ public void testExpandWithEmptyIndexReturnsZeroResults() {
+ //We make sure the index is cleared
+
+ clearIndex();
+ assertU(commit());
+
+ ModifiableSolrParams params = new ModifiableSolrParams();
+ params.add("q", "*:*");
+ params.add("fq", "{!collapse field=group_s}");
+ params.add("expand" ,"true");
+ params.add("expand.rows", "10");
+
+ assertQ(req(params), "*[count(//doc)=0]");
+ }
}