Skip to content

Commit

Permalink
[BUG] CompletionSuggestSearchIT.testSkipDuplicates is flaky (opensear…
Browse files Browse the repository at this point in the history
…ch-project#8963)

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
Signed-off-by: Shivansh Arora <hishiv@amazon.com>
  • Loading branch information
reta authored and shiv0408 committed Apr 25, 2024
1 parent 5b8811b commit b2a015f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ private void searchLeaf(LeafReaderContext ctx, Weight weight, Collector collecto
}
}
}

// Note: this is called if collection ran successfully, including the above special cases of
// CollectionTerminatedException and TimeExceededException, but no other exception.
leafCollector.finish();
}

private Weight wrapWeight(Weight weight) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.lucene.search.BulkScorer;
import org.apache.lucene.search.CollectionTerminatedException;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.LeafCollector;
import org.apache.lucene.search.Weight;
import org.apache.lucene.search.suggest.document.CompletionQuery;
import org.apache.lucene.search.suggest.document.TopSuggestDocs;
Expand Down Expand Up @@ -108,15 +109,21 @@ private static void suggest(IndexSearcher searcher, CompletionQuery query, TopSu
for (LeafReaderContext context : searcher.getIndexReader().leaves()) {
BulkScorer scorer = weight.bulkScorer(context);
if (scorer != null) {
LeafCollector leafCollector = null;
try {
scorer.score(collector.getLeafCollector(context), context.reader().getLiveDocs());
leafCollector = collector.getLeafCollector(context);
scorer.score(leafCollector, context.reader().getLiveDocs());
} catch (CollectionTerminatedException e) {
// collection was terminated prematurely
// continue with the following leaf
}
// Note: this is called if collection ran successfully, including the above special cases of
// CollectionTerminatedException and TimeExceededException, but no other exception.
if (leafCollector != null) {
leafCollector.finish();
}
}
}
collector.finish();
}

@Override
Expand Down

0 comments on commit b2a015f

Please sign in to comment.