• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java LeafBucketCollectorBase类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.elasticsearch.search.aggregations.LeafBucketCollectorBase的典型用法代码示例。如果您正苦于以下问题:Java LeafBucketCollectorBase类的具体用法?Java LeafBucketCollectorBase怎么用?Java LeafBucketCollectorBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LeafBucketCollectorBase类属于org.elasticsearch.search.aggregations包,在下文中一共展示了LeafBucketCollectorBase类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        final LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final SortedNumericDoubleValues values = valuesSource.doubleValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {
        @Override
        public void collect(int doc, long bucket) throws IOException {
            counts = bigArrays.grow(counts, bucket + 1);
            sums = bigArrays.grow(sums, bucket + 1);

            values.setDocument(doc);
            final int valueCount = values.count();
            counts.increment(bucket, valueCount);
            double sum = 0;
            for (int i = 0; i < valueCount; i++) {
                sum += values.valueAt(i);
            }
            sums.increment(bucket, sum);
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:AvgAggregator.java


示例2: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        final LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final SortedNumericDoubleValues values = valuesSource.doubleValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {
        @Override
        public void collect(int doc, long bucket) throws IOException {
            sums = bigArrays.grow(sums, bucket + 1);
            values.setDocument(doc);
            final int valuesCount = values.count();
            double sum = 0;
            for (int i = 0; i < valuesCount; i++) {
                sum += values.valueAt(i);
            }
            sums.increment(bucket, sum);
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:SumAggregator.java


示例3: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        final LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
}
    final BigArrays bigArrays = context.bigArrays();
    final SortedNumericDoubleValues allValues = valuesSource.doubleValues(ctx);
    final NumericDoubleValues values = MultiValueMode.MAX.select(allValues, Double.NEGATIVE_INFINITY);
    return new LeafBucketCollectorBase(sub, allValues) {

        @Override
        public void collect(int doc, long bucket) throws IOException {
            if (bucket >= maxes.size()) {
                long from = maxes.size();
                maxes = bigArrays.grow(maxes, bucket + 1);
                maxes.fill(from, maxes.size(), Double.NEGATIVE_INFINITY);
            }
            final double value = values.get(doc);
            double max = maxes.get(bucket);
            max = Math.max(max, value);
            maxes.set(bucket, max);
        }

    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:MaxAggregator.java


示例4: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        final LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final SortedBinaryDocValues values = valuesSource.bytesValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {

        @Override
        public void collect(int doc, long bucket) throws IOException {
            counts = bigArrays.grow(counts, bucket + 1);
            values.setDocument(doc);
            counts.increment(bucket, values.count());
        }

    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:ValueCountAggregator.java


示例5: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        final LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final SortedNumericDoubleValues allValues = valuesSource.doubleValues(ctx);
    final NumericDoubleValues values = MultiValueMode.MIN.select(allValues, Double.POSITIVE_INFINITY);
    return new LeafBucketCollectorBase(sub, allValues) {

        @Override
        public void collect(int doc, long bucket) throws IOException {
            if (bucket >= mins.size()) {
                long from = mins.size();
                mins = bigArrays.grow(mins, bucket + 1);
                mins.fill(from, mins.size(), Double.POSITIVE_INFINITY);
            }
            final double value = values.get(doc);
            double min = mins.get(bucket);
            min = Math.min(min, value);
            mins.set(bucket, min);
        }

    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:MinAggregator.java


示例6: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        final LeafBucketCollector sub) throws IOException {

    final Bits docsWithValue;
    if (valuesSource != null) {
        docsWithValue = valuesSource.docsWithValue(ctx);
    } else {
        docsWithValue = new Bits.MatchNoBits(ctx.reader().maxDoc());
    }
    return new LeafBucketCollectorBase(sub, docsWithValue) {
        @Override
        public void collect(int doc, long bucket) throws IOException {
            if (docsWithValue != null && !docsWithValue.get(doc)) {
                collectBucket(sub, doc, bucket);
            }
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:MissingAggregator.java


示例7: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@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));
            }
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:FiltersAggregator.java


示例8: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        final LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final SortedNumericDoubleValues values = valuesSource.doubleValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {
        @Override
        public void collect(int doc, long bucket) throws IOException {
            states = bigArrays.grow(states, bucket + 1);

            TDigestState state = states.get(bucket);
            if (state == null) {
                state = new TDigestState(compression);
                states.set(bucket, state);
            }

            values.setDocument(doc);
            final int valueCount = values.count();
            for (int i = 0; i < valueCount; i++) {
                state.add(values.valueAt(i));
            }
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:AbstractTDigestPercentilesAggregator.java


示例9: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        final LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final SortedNumericDoubleValues values = valuesSource.doubleValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {
        @Override
        public void collect(int doc, long bucket) throws IOException {
            if (bucket >= counts.size()) {
                final long from = counts.size();
                final long overSize = BigArrays.overSize(bucket + 1);
                counts = bigArrays.resize(counts, overSize);
                sums = bigArrays.resize(sums, overSize);
                mins = bigArrays.resize(mins, overSize);
                maxes = bigArrays.resize(maxes, overSize);
                mins.fill(from, overSize, Double.POSITIVE_INFINITY);
                maxes.fill(from, overSize, Double.NEGATIVE_INFINITY);
            }

            values.setDocument(doc);
            final int valuesCount = values.count();
            counts.increment(bucket, valuesCount);
            double sum = 0;
            double min = mins.get(bucket);
            double max = maxes.get(bucket);
            for (int i = 0; i < valuesCount; i++) {
                double value = values.valueAt(i);
                sum += value;
                min = Math.min(min, value);
                max = Math.max(max, value);
            }
            sums.increment(bucket, sum);
            mins.set(bucket, min);
            maxes.set(bucket, max);
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:StatsAggregator.java


示例10: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final MultiGeoPointValues values = valuesSource.geoPointValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {
        @Override
        public void collect(int doc, long bucket) throws IOException {
            centroids = bigArrays.grow(centroids, bucket + 1);
            counts = bigArrays.grow(counts, bucket + 1);

            values.setDocument(doc);
            final int valueCount = values.count();
            if (valueCount > 0) {
                double[] pt = new double[2];
                // get the previously accumulated number of counts
                long prevCounts = counts.get(bucket);
                // increment by the number of points for this document
                counts.increment(bucket, valueCount);
                // get the previous GeoPoint if a moving avg was computed
                if (prevCounts > 0) {
                    final long mortonCode = centroids.get(bucket);
                    pt[0] = GeoPointField.decodeLongitude(mortonCode);
                    pt[1] = GeoPointField.decodeLatitude(mortonCode);
                }
                // update the moving average
                for (int i = 0; i < valueCount; ++i) {
                    GeoPoint value = values.valueAt(i);
                    pt[0] = pt[0] + (value.getLon() - pt[0]) / ++prevCounts;
                    pt[1] = pt[1] + (value.getLat() - pt[1]) / prevCounts;
                }
                // TODO: we do not need to interleave the lat and lon bits here
                // should we just store them contiguously?
                centroids.set(bucket, GeoPointField.encodeLatLon(pt[1], pt[0]));
            }
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:GeoCentroidAggregator.java


示例11: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        final LeafBucketCollector sub) throws IOException {
    return new LeafBucketCollectorBase(super.getLeafCollector(ctx, sub), null) {
        @Override
        public void collect(int doc, long bucket) throws IOException {
            super.collect(doc, bucket);
            numCollectedDocs++;
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:SignificantStringTermsAggregator.java


示例12: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@Override
public LeafBucketCollector getLeafCollector(final LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException {
    IndexReaderContext topLevelContext = ReaderUtil.getTopLevelContext(ctx);
    IndexSearcher searcher = new IndexSearcher(topLevelContext);
    searcher.setQueryCache(null);
    Weight weight = searcher.createNormalizedWeight(childFilter, false);
    Scorer childDocsScorer = weight.scorer(ctx);

    final BitSet parentDocs = parentFilter.getBitSet(ctx);
    final DocIdSetIterator childDocs = childDocsScorer != null ? childDocsScorer.iterator() : null;
    return new LeafBucketCollectorBase(sub, null) {
        @Override
        public void collect(int parentDoc, long bucket) throws IOException {
            // if parentDoc is 0 then this means that this parent doesn't have child docs (b/c these appear always before the parent
            // doc), so we can skip:
            if (parentDoc == 0 || parentDocs == null || childDocs == null) {
                return;
            }

            final int prevParentDoc = parentDocs.prevSetBit(parentDoc - 1);
            int childDocId = childDocs.docID();
            if (childDocId <= prevParentDoc) {
                childDocId = childDocs.advance(prevParentDoc + 1);
            }

            for (; childDocId < parentDoc; childDocId = childDocs.nextDoc()) {
                collectBucket(sub, childDocId, bucket);
            }
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:NestedAggregator.java


示例13: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@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);
            }
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:FilterAggregator.java


示例14: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final MultiGeoPointValues values = valuesSource.geoPointValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {
        @Override
        public void collect(int doc, long bucket) throws IOException {
            centroids = bigArrays.grow(centroids, bucket + 1);
            counts = bigArrays.grow(counts, bucket + 1);

            values.setDocument(doc);
            final int valueCount = values.count();
            if (valueCount > 0) {
                double[] pt = new double[2];
                // get the previously accumulated number of counts
                long prevCounts = counts.get(bucket);
                // increment by the number of points for this document
                counts.increment(bucket, valueCount);
                // get the previous GeoPoint if a moving avg was computed
                if (prevCounts > 0) {
                    final GeoPoint centroid = GeoPoint.fromIndexLong(centroids.get(bucket));
                    pt[0] = centroid.lon();
                    pt[1] = centroid.lat();
                }
                // update the moving average
                for (int i = 0; i < valueCount; ++i) {
                    GeoPoint value = values.valueAt(i);
                    pt[0] = pt[0] + (value.getLon() - pt[0]) / ++prevCounts;
                    pt[1] = pt[1] + (value.getLat() - pt[1]) / prevCounts;
                }
                centroids.set(bucket, GeoEncodingUtils.mortonHash(pt[0], pt[1]));
            }
        }
    };
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:39,代码来源:GeoCentroidAggregator.java


示例15: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
                                            final LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final SortedBinaryDocValues values = valuesSource.bytesValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {
        @Override
        public void collect(int doc, long bucket) throws IOException {
            hyperLogLogPlusPlusObjectArray = bigArrays.grow(hyperLogLogPlusPlusObjectArray, bucket + 1);
            values.setDocument(doc);
            final int valuesCount = values.count();
            HyperLogLogPlus hll;
            for (int i = 0; i < valuesCount; i++) {
                hll = deserializeHyperLogLogPlus(values.valueAt(i));
                    HyperLogLogPlus current = hyperLogLogPlusPlusObjectArray.get(bucket);
                    if (current == null) {
                        hyperLogLogPlusPlusObjectArray.set(bucket, hll);
                    } else {
                        try {
                            hyperLogLogPlusPlusObjectArray.set(bucket, (HyperLogLogPlus) hll.merge(current));
                        } catch (CardinalityMergeException cme) {
                            throw new ElasticsearchGenerationException("Failed to merge HyperLogLogPlus structures  ", cme);
                        }
                    }

            }
        }
    };
}
 
开发者ID:bazaarvoice,项目名称:elasticsearch-hyperloglog,代码行数:33,代码来源:HyperUniqueSumAggregator.java


示例16: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        LeafBucketCollector sub) {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final MultiGeoPointValues values = valuesSource.geoPointValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {
        @Override
        public void collect(int doc, long bucket) throws IOException {
            if (bucket >= tops.size()) {
                long from = tops.size();
                tops = bigArrays.grow(tops, bucket + 1);
                tops.fill(from, tops.size(), Double.NEGATIVE_INFINITY);
                bottoms = bigArrays.resize(bottoms, tops.size());
                bottoms.fill(from, bottoms.size(), Double.POSITIVE_INFINITY);
                posLefts = bigArrays.resize(posLefts, tops.size());
                posLefts.fill(from, posLefts.size(), Double.POSITIVE_INFINITY);
                posRights = bigArrays.resize(posRights, tops.size());
                posRights.fill(from, posRights.size(), Double.NEGATIVE_INFINITY);
                negLefts = bigArrays.resize(negLefts, tops.size());
                negLefts.fill(from, negLefts.size(), Double.POSITIVE_INFINITY);
                negRights = bigArrays.resize(negRights, tops.size());
                negRights.fill(from, negRights.size(), Double.NEGATIVE_INFINITY);
            }

            values.setDocument(doc);
            final int valuesCount = values.count();

            for (int i = 0; i < valuesCount; ++i) {
                GeoPoint value = values.valueAt(i);
                double top = tops.get(bucket);
                if (value.lat() > top) {
                    top = value.lat();
                }
                double bottom = bottoms.get(bucket);
                if (value.lat() < bottom) {
                    bottom = value.lat();
                }
                double posLeft = posLefts.get(bucket);
                if (value.lon() >= 0 && value.lon() < posLeft) {
                    posLeft = value.lon();
                }
                double posRight = posRights.get(bucket);
                if (value.lon() >= 0 && value.lon() > posRight) {
                    posRight = value.lon();
                }
                double negLeft = negLefts.get(bucket);
                if (value.lon() < 0 && value.lon() < negLeft) {
                    negLeft = value.lon();
                }
                double negRight = negRights.get(bucket);
                if (value.lon() < 0 && value.lon() > negRight) {
                    negRight = value.lon();
                }
                tops.set(bucket, top);
                bottoms.set(bucket, bottom);
                posLefts.set(bucket, posLeft);
                posRights.set(bucket, posRight);
                negLefts.set(bucket, negLeft);
                negRights.set(bucket, negRight);
            }
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:67,代码来源:GeoBoundsAggregator.java


示例17: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        final LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final SortedNumericDoubleValues values = valuesSource.doubleValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {

        @Override
        public void collect(int doc, long bucket) throws IOException {
            if (bucket >= counts.size()) {
                final long from = counts.size();
                final long overSize = BigArrays.overSize(bucket + 1);
                counts = bigArrays.resize(counts, overSize);
                sums = bigArrays.resize(sums, overSize);
                mins = bigArrays.resize(mins, overSize);
                maxes = bigArrays.resize(maxes, overSize);
                sumOfSqrs = bigArrays.resize(sumOfSqrs, overSize);
                mins.fill(from, overSize, Double.POSITIVE_INFINITY);
                maxes.fill(from, overSize, Double.NEGATIVE_INFINITY);
            }

            values.setDocument(doc);
            final int valuesCount = values.count();
            counts.increment(bucket, valuesCount);
            double sum = 0;
            double sumOfSqr = 0;
            double min = mins.get(bucket);
            double max = maxes.get(bucket);
            for (int i = 0; i < valuesCount; i++) {
                double value = values.valueAt(i);
                sum += value;
                sumOfSqr += value * value;
                min = Math.min(min, value);
                max = Math.max(max, value);
            }
            sums.increment(bucket, sum);
            sumOfSqrs.increment(bucket, sumOfSqr);
            mins.set(bucket, min);
            maxes.set(bucket, max);
        }

    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:47,代码来源:ExtendedStatsAggregator.java


示例18: getLeafCollector

import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; //导入依赖的package包/类
@Override
public LeafBucketCollector getLeafCollector(final LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException {
    // Reset parentFilter, so we resolve the parentDocs for each new segment being searched
    this.parentFilter = null;
    final IndexReaderContext topLevelContext = ReaderUtil.getTopLevelContext(ctx);
    final IndexSearcher searcher = new IndexSearcher(topLevelContext);
    searcher.setQueryCache(null);
    final Weight weight = searcher.createNormalizedWeight(childFilter, false);
    Scorer childDocsScorer = weight.scorer(ctx);
    if (childDocsScorer == null) {
        childDocs = null;
    } else {
        childDocs = childDocsScorer.iterator();
    }

    return new LeafBucketCollectorBase(sub, null) {
        @Override
        public void collect(int parentDoc, long bucket) throws IOException {
            // here we translate the parent doc to a list of its nested docs, and then call super.collect for evey one of them so they'll be collected

            // if parentDoc is 0 then this means that this parent doesn't have child docs (b/c these appear always before the parent doc), so we can skip:
            if (parentDoc == 0 || childDocs == null) {
                return;
            }
            if (parentFilter == null) {
                // The aggs are instantiated in reverse, first the most inner nested aggs and lastly the top level aggs
                // So at the time a nested 'nested' aggs is parsed its closest parent nested aggs hasn't been constructed.
                // So the trick is to set at the last moment just before needed and we can use its child filter as the
                // parent filter.

                // Additional NOTE: Before this logic was performed in the setNextReader(...) method, but the the assumption
                // that aggs instances are constructed in reverse doesn't hold when buckets are constructed lazily during
                // aggs execution
                Query parentFilterNotCached = findClosestNestedPath(parent());
                if (parentFilterNotCached == null) {
                    parentFilterNotCached = Queries.newNonNestedFilter();
                }
                parentFilter = context.searchContext().bitsetFilterCache().getBitSetProducer(parentFilterNotCached);
                parentDocs = parentFilter.getBitSet(ctx);
                if (parentDocs == null) {
                    // There are no parentDocs in the segment, so return and set childDocs to null, so we exit early for future invocations.
                    childDocs = null;
                    return;
                }
            }

            final int prevParentDoc = parentDocs.prevSetBit(parentDoc - 1);
            int childDocId = childDocs.docID();
            if (childDocId <= prevParentDoc) {
                childDocId = childDocs.advance(prevParentDoc + 1);
            }

            for (; childDocId < parentDoc; childDocId = childDocs.nextDoc()) {
                collectBucket(sub, childDocId, bucket);
            }
        }
    };
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:59,代码来源:NestedAggregator.java



注:本文中的org.elasticsearch.search.aggregations.LeafBucketCollectorBase类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ProjectionFactory类代码示例发布时间:2022-05-23
下一篇:
Java IEntityParameterCallable类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap