SOLR-9616 Solr throws exception when expand=true on empty index

This commit is contained in:
Ishan Chattopadhyaya 2016-12-01 00:46:58 +05:30
parent 9eaea79f5c
commit e64bcb37ff
3 changed files with 23 additions and 0 deletions

View File

@ -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
----------------------

View File

@ -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;

View File

@ -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]");
}
}