Skip to content

Commit b2a015f

Browse files
retashiv0408
authored andcommitted
[BUG] CompletionSuggestSearchIT.testSkipDuplicates is flaky (opensearch-project#8963)
Signed-off-by: Andriy Redko <[email protected]> Signed-off-by: Shivansh Arora <[email protected]>
1 parent 5b8811b commit b2a015f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ private void searchLeaf(LeafReaderContext ctx, Weight weight, Collector collecto
343343
}
344344
}
345345
}
346+
347+
// Note: this is called if collection ran successfully, including the above special cases of
348+
// CollectionTerminatedException and TimeExceededException, but no other exception.
349+
leafCollector.finish();
346350
}
347351

348352
private Weight wrapWeight(Weight weight) {

server/src/main/java/org/opensearch/search/suggest/completion/CompletionSuggester.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.lucene.search.BulkScorer;
3636
import org.apache.lucene.search.CollectionTerminatedException;
3737
import org.apache.lucene.search.IndexSearcher;
38+
import org.apache.lucene.search.LeafCollector;
3839
import org.apache.lucene.search.Weight;
3940
import org.apache.lucene.search.suggest.document.CompletionQuery;
4041
import org.apache.lucene.search.suggest.document.TopSuggestDocs;
@@ -108,15 +109,21 @@ private static void suggest(IndexSearcher searcher, CompletionQuery query, TopSu
108109
for (LeafReaderContext context : searcher.getIndexReader().leaves()) {
109110
BulkScorer scorer = weight.bulkScorer(context);
110111
if (scorer != null) {
112+
LeafCollector leafCollector = null;
111113
try {
112-
scorer.score(collector.getLeafCollector(context), context.reader().getLiveDocs());
114+
leafCollector = collector.getLeafCollector(context);
115+
scorer.score(leafCollector, context.reader().getLiveDocs());
113116
} catch (CollectionTerminatedException e) {
114117
// collection was terminated prematurely
115118
// continue with the following leaf
116119
}
120+
// Note: this is called if collection ran successfully, including the above special cases of
121+
// CollectionTerminatedException and TimeExceededException, but no other exception.
122+
if (leafCollector != null) {
123+
leafCollector.finish();
124+
}
117125
}
118126
}
119-
collector.finish();
120127
}
121128

122129
@Override

0 commit comments

Comments
 (0)