Java Code Examples for org.elasticsearch.common.lucene.Lucene#asSequentialAccessBits()

The following examples show how to use org.elasticsearch.common.lucene.Lucene#asSequentialAccessBits() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FiltersAggregator.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        final LeafBucketCollector sub) throws IOException {
    // no need to provide deleted docs to the filter
    final Bits[] bits = new Bits[filters.length];
    for (int i = 0; i < filters.length; ++i) {
        bits[i] = Lucene.asSequentialAccessBits(ctx.reader().maxDoc(), filters[i].scorer(ctx));
    }
    return new LeafBucketCollectorBase(sub, null) {
        @Override
        public void collect(int doc, long bucket) throws IOException {
            boolean matched = false;
            for (int i = 0; i < bits.length; i++) {
                if (bits[i].get(doc)) {
                    collectBucket(sub, doc, bucketOrd(bucket, i));
                    matched = true;
                }
            }
            if (showOtherBucket && !matched) {
                collectBucket(sub, doc, bucketOrd(bucket, bits.length));
            }
        }
    };
}
 
Example 2
Source File: FilterAggregator.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        final LeafBucketCollector sub) throws IOException {
    // no need to provide deleted docs to the filter
    final Bits bits = Lucene.asSequentialAccessBits(ctx.reader().maxDoc(), filter.scorer(ctx));
    return new LeafBucketCollectorBase(sub, null) {
        @Override
        public void collect(int doc, long bucket) throws IOException {
            if (bits.get(doc)) {
                collectBucket(sub, doc, bucket);
            }
        }
    };
}
 
Example 3
Source File: FiltersFunctionScoreQuery.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private FiltersFunctionFactorScorer functionScorer(LeafReaderContext context) throws IOException {
    Scorer subQueryScorer = subQueryWeight.scorer(context);
    if (subQueryScorer == null) {
        return null;
    }
    final LeafScoreFunction[] functions = new LeafScoreFunction[filterFunctions.length];
    final Bits[] docSets = new Bits[filterFunctions.length];
    for (int i = 0; i < filterFunctions.length; i++) {
        FilterFunction filterFunction = filterFunctions[i];
        functions[i] = filterFunction.function.getLeafScoreFunction(context);
        Scorer filterScorer = filterWeights[i].scorer(context);
        docSets[i] = Lucene.asSequentialAccessBits(context.reader().maxDoc(), filterScorer);
    }
    return new FiltersFunctionFactorScorer(this, subQueryScorer, scoreMode, filterFunctions, maxBoost, functions, docSets, combineFunction, needsScores);
}
 
Example 4
Source File: FilteredCollector.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@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
        public void collect(int doc) throws IOException {
            if (bits.get(doc)) {
                in.collect(doc);
            }
        }
    };
}