use of org.apache.lucene.search.CollectionTerminatedException in project elasticsearch by elastic.
the class CompletionSuggester method suggest.
private static void suggest(IndexSearcher searcher, CompletionQuery query, TopSuggestDocsCollector collector) throws IOException {
query = (CompletionQuery) query.rewrite(searcher.getIndexReader());
Weight weight = query.createWeight(searcher, collector.needsScores());
for (LeafReaderContext context : searcher.getIndexReader().leaves()) {
BulkScorer scorer = weight.bulkScorer(context);
if (scorer != null) {
try {
scorer.score(collector.getLeafCollector(context), context.reader().getLiveDocs());
} catch (CollectionTerminatedException e) {
// collection was terminated prematurely
// continue with the following leaf
}
}
}
}
use of org.apache.lucene.search.CollectionTerminatedException in project lucene-solr by apache.
the class SuggestIndexSearcher method suggest.
/**
* Lower-level suggest API.
* Collects completion hits through <code>collector</code> for <code>query</code>.
*
* <p>{@link TopSuggestDocsCollector#collect(int, CharSequence, CharSequence, float)}
* is called for every matching completion hit.
*/
public void suggest(CompletionQuery query, TopSuggestDocsCollector collector) throws IOException {
// TODO use IndexSearcher.rewrite instead
// have to implement equals() and hashCode() in CompletionQuerys and co
query = (CompletionQuery) query.rewrite(getIndexReader());
Weight weight = query.createWeight(this, collector.needsScores(), 1f);
for (LeafReaderContext context : getIndexReader().leaves()) {
BulkScorer scorer = weight.bulkScorer(context);
if (scorer != null) {
try {
scorer.score(collector.getLeafCollector(context), context.reader().getLiveDocs());
} catch (CollectionTerminatedException e) {
// collection was terminated prematurely
// continue with the following leaf
}
}
}
}
use of org.apache.lucene.search.CollectionTerminatedException in project neo4j by neo4j.
the class NodeRangeDocumentLabelScanStorageStrategyTest method newIndexPartitionMock.
private WritableIndexPartition newIndexPartitionMock(IndexWriter indexWriter, Document... documents) throws IOException {
WritableIndexPartition partition = mock(WritableIndexPartition.class);
PartitionSearcher partitionSearcher = mock(PartitionSearcher.class);
when(partition.acquireSearcher()).thenReturn(partitionSearcher);
when(partition.getIndexWriter()).thenReturn(indexWriter);
IndexSearcher searcher = mock(IndexSearcher.class);
when(partitionSearcher.getIndexSearcher()).thenReturn(searcher);
for (int i = 0; i < documents.length; i++) {
int docId = i;
doAnswer(invocation -> {
FirstHitCollector collector = (FirstHitCollector) invocation.getArguments()[1];
try {
collector.collect(docId);
} catch (CollectionTerminatedException swallow) {
}
return null;
}).when(searcher).search(eq(new TermQuery(format.rangeTerm(documents[i]))), any(FirstHitCollector.class));
when(searcher.doc(i)).thenReturn(documents[i]);
}
return partition;
}
Aggregations