Example usage for org.apache.lucene.search FilterLeafCollector FilterLeafCollector

List of usage examples for org.apache.lucene.search FilterLeafCollector FilterLeafCollector

Introduction

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

Prototype

public FilterLeafCollector(LeafCollector in) 

Source Link

Document

Sole constructor.

Usage

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

License:Apache License

@Override
public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
    Sort segmentSort = context.reader().getMetaData().getSort();
    if (segmentSort != null && canEarlyTerminate(sort, segmentSort) == false) {
        throw new IllegalStateException("Cannot early terminate with sort order " + sort
                + " if segments are sorted with " + segmentSort);
    }/*w  w  w .  ja v  a2  s. c o  m*/

    if (segmentSort != null) {
        // segment is sorted, can early-terminate
        return new FilterLeafCollector(super.getLeafCollector(context)) {
            private int numCollected;

            @Override
            public void collect(int doc) throws IOException {
                super.collect(doc);
                if (++numCollected >= numDocsToCollect) {
                    terminatedEarly.set(true);
                    throw new CollectionTerminatedException();
                }
            }

        };
    } else {
        return super.getLeafCollector(context);
    }
}

From source file:org.codelibs.elasticsearch.common.lucene.search.FilteredCollector.java

License:Apache License

@Override
public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
    final Scorer filterScorer = filter.scorer(context);
    final LeafCollector in = collector.getLeafCollector(context);
    final Bits bits = Lucene.asSequentialAccessBits(context.reader().maxDoc(), filterScorer);

    return new FilterLeafCollector(in) {
        @Override/*  w ww  .  java2  s  .  c om*/
        public void collect(int doc) throws IOException {
            if (bits.get(doc)) {
                in.collect(doc);
            }
        }
    };
}

From source file:org.codelibs.elasticsearch.search.profile.query.ProfileCollector.java

License:Apache License

@Override
public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
    final long start = System.nanoTime();
    final LeafCollector inLeafCollector;
    try {//  w w  w.  ja va2s.c om
        inLeafCollector = super.getLeafCollector(context);
    } finally {
        time += Math.max(1, System.nanoTime() - start);
    }
    return new FilterLeafCollector(inLeafCollector) {

        @Override
        public void collect(int doc) throws IOException {
            final long start = System.nanoTime();
            try {
                super.collect(doc);
            } finally {
                time += Math.max(1, System.nanoTime() - start);
            }
        }

        @Override
        public void setScorer(Scorer scorer) throws IOException {
            final long start = System.nanoTime();
            try {
                super.setScorer(scorer);
            } finally {
                time += Math.max(1, System.nanoTime() - start);
            }
        }
    };
}

From source file:org.elasticsearch.search.query.EarlyTerminatingCollector.java

License:Apache License

@Override
public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
    if (numCollected >= maxCountHits) {
        throw new CollectionTerminatedException();
    }// ww w  .j  a  v a 2 s  .co  m
    return new FilterLeafCollector(super.getLeafCollector(context)) {
        @Override
        public void collect(int doc) throws IOException {
            super.collect(doc);
            if (++numCollected >= maxCountHits) {
                terminatedEarly = true;
                throw new CollectionTerminatedException();
            }
        };
    };
}