mirror of https://github.com/apache/lucene.git
SOLR-9616 Solr throws exception when expand=true on empty index
This commit is contained in:
parent
9eaea79f5c
commit
e64bcb37ff
|
@ -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
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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]");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue