Search in sources :

Example 1 with CollectionTerminatedException

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
            }
        }
    }
}
Also used : CollectionTerminatedException(org.apache.lucene.search.CollectionTerminatedException) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) BulkScorer(org.apache.lucene.search.BulkScorer) Weight(org.apache.lucene.search.Weight)

Example 2 with CollectionTerminatedException

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
            }
        }
    }
}
Also used : CollectionTerminatedException(org.apache.lucene.search.CollectionTerminatedException) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) BulkScorer(org.apache.lucene.search.BulkScorer) Weight(org.apache.lucene.search.Weight)

Example 3 with CollectionTerminatedException

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;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TermQuery(org.apache.lucene.search.TermQuery) PartitionSearcher(org.neo4j.kernel.api.impl.index.partition.PartitionSearcher) CollectionTerminatedException(org.apache.lucene.search.CollectionTerminatedException) WritableIndexPartition(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition) FirstHitCollector(org.neo4j.kernel.api.impl.index.collector.FirstHitCollector)

Aggregations

CollectionTerminatedException (org.apache.lucene.search.CollectionTerminatedException)3 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)2 BulkScorer (org.apache.lucene.search.BulkScorer)2 Weight (org.apache.lucene.search.Weight)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 TermQuery (org.apache.lucene.search.TermQuery)1 FirstHitCollector (org.neo4j.kernel.api.impl.index.collector.FirstHitCollector)1 PartitionSearcher (org.neo4j.kernel.api.impl.index.partition.PartitionSearcher)1 WritableIndexPartition (org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition)1