Example usage for org.apache.lucene.search Collector getLeafCollector

List of usage examples for org.apache.lucene.search Collector getLeafCollector

Introduction

In this page you can find the example usage for org.apache.lucene.search Collector getLeafCollector.

Prototype

LeafCollector getLeafCollector(LeafReaderContext context) throws IOException;

Source Link

Document

Create a new LeafCollector collector to collect the given context.

Usage

From source file:com.lucene.MyIndexSearcher.java

License:Apache License

protected void search(List<LeafReaderContext> leaves, Weight weight, Collector collector) throws IOException {
    for (LeafReaderContext ctx : leaves) {
        final LeafCollector leafCollector;
        try {// w  ww  .j  a  v  a 2 s  .com
            leafCollector = collector.getLeafCollector(ctx);
        } catch (CollectionTerminatedException e) {
            continue;
        }
        BulkScorer scorer = weight.bulkScorer(ctx);
        if (scorer != null) {
            try {
                scorer.score(leafCollector, ctx.reader().getLiveDocs());
            } catch (CollectionTerminatedException e) {
            }
        }

    }
}

From source file:org.apache.solr.search.DocSetUtil.java

License:Apache License

public static void collectSortedDocSet(DocSet docs, IndexReader reader, Collector collector)
        throws IOException {
    // TODO add SortedDocSet sub-interface and take that.
    // TODO collectUnsortedDocSet: iterate segment, then all docSet per segment.

    final List<LeafReaderContext> leaves = reader.leaves();
    final Iterator<LeafReaderContext> ctxIt = leaves.iterator();
    int segBase = 0;
    int segMax;//from ww w. j  a va2  s . c om
    int adjustedMax = 0;
    LeafReaderContext ctx = null;
    LeafCollector leafCollector = null;
    for (DocIterator docsIt = docs.iterator(); docsIt.hasNext();) {
        final int doc = docsIt.nextDoc();
        if (doc >= adjustedMax) {
            do {
                ctx = ctxIt.next();
                segBase = ctx.docBase;
                segMax = ctx.reader().maxDoc();
                adjustedMax = segBase + segMax;
            } while (doc >= adjustedMax);
            leafCollector = collector.getLeafCollector(ctx);
        }
        if (doc < segBase) {
            throw new IllegalStateException("algorithm expects sorted DocSet but wasn't: " + docs.getClass());
        }
        leafCollector.collect(doc - segBase); // per-seg collectors
    }
}

From source file:org.neo4j.kernel.api.impl.index.collector.DocValuesCollector.java

License:Open Source License

private void replayTo(Collector collector) throws IOException {
    for (MatchingDocs docs : getMatchingDocs()) {
        LeafCollector leafCollector = collector.getLeafCollector(docs.context);
        Scorer scorer;//from www  .j  a  v a 2s.  c om
        DocIdSetIterator idIterator = docs.docIdSet.iterator();
        if (isKeepScores()) {
            scorer = new ReplayingScorer(docs.scores);
        } else {
            scorer = new ConstantScoreScorer(null, Float.NaN, idIterator);
        }
        leafCollector.setScorer(scorer);
        int doc;
        while ((doc = idIterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
            leafCollector.collect(doc);
        }
    }
}

From source file:org.neo4j.kernel.api.impl.index.DocValuesCollector.java

License:Open Source License

private void replayTo(Collector collector) throws IOException {
    for (MatchingDocs docs : getMatchingDocs()) {
        LeafCollector leafCollector = collector.getLeafCollector(docs.context);
        Scorer scorer;/*from   ww  w. j av  a  2s. c om*/
        DocIdSetIterator disi = docs.docIdSet.iterator();
        if (isKeepScores()) {
            scorer = new ReplayingScorer(docs.scores);
        } else {
            scorer = new ConstantScoreScorer(null, Float.NaN, disi);
        }
        leafCollector.setScorer(scorer);
        int doc;
        while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
            leafCollector.collect(doc);
        }
    }
}