From 411b7fd51861b77e4cf2644c02dd6c6d92011a1f Mon Sep 17 00:00:00 2001 From: Christine Poerschke Date: Fri, 29 Sep 2023 12:14:50 +0100 Subject: [PATCH] SuggestIndexSearcher.suggest catches any CollectionTerminatedException (theoretically) thrown by getLeafCollector (#12609) --- .../search/suggest/document/SuggestIndexSearcher.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/SuggestIndexSearcher.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/SuggestIndexSearcher.java index 0c88359029b..f89efeffb06 100644 --- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/SuggestIndexSearcher.java +++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/SuggestIndexSearcher.java @@ -68,8 +68,9 @@ public class SuggestIndexSearcher extends IndexSearcher { for (LeafReaderContext context : getIndexReader().leaves()) { BulkScorer scorer = weight.bulkScorer(context); if (scorer != null) { - LeafCollector leafCollector = collector.getLeafCollector(context); + LeafCollector leafCollector = null; try { + leafCollector = collector.getLeafCollector(context); scorer.score(leafCollector, context.reader().getLiveDocs()); } catch ( @SuppressWarnings("unused") @@ -77,7 +78,9 @@ public class SuggestIndexSearcher extends IndexSearcher { // collection was terminated prematurely // continue with the following leaf } - leafCollector.finish(); + if (leafCollector != null) { + leafCollector.finish(); + } } } }