Package org.elasticsearch.common.trove.map.hash

Examples of org.elasticsearch.common.trove.map.hash.TShortIntHashMap


    @Override public Facet reduce(String name, List<Facet> facets) {
        if (facets.size() == 1) {
            return facets.get(0);
        }
        InternalShortTermsFacet first = (InternalShortTermsFacet) facets.get(0);
        TShortIntHashMap aggregated = CacheRecycler.popShortIntMap();
        long missing = 0;
        long total = 0;
        for (Facet facet : facets) {
            InternalShortTermsFacet mFacet = (InternalShortTermsFacet) facet;
            missing += mFacet.missingCount();
            total += mFacet.totalCount();
            for (ShortEntry entry : mFacet.entries) {
                aggregated.adjustOrPutValue(entry.term, entry.count(), entry.count());
            }
        }

        BoundedTreeSet<ShortEntry> ordered = new BoundedTreeSet<ShortEntry>(first.comparatorType.comparator(), first.requiredSize);
        for (TShortIntIterator it = aggregated.iterator(); it.hasNext(); ) {
            it.advance();
            ordered.add(new ShortEntry(it.key(), it.value()));
        }
        first.entries = ordered;
        first.missing = missing;
View Full Code Here


    @Override protected void doCollect(int doc) throws IOException {
        fieldData.forEachValueInDoc(doc, aggregator);
    }

    @Override public Facet facet() {
        TShortIntHashMap facets = aggregator.facets();
        if (facets.isEmpty()) {
            CacheRecycler.pushShortIntMap(facets);
            return new InternalShortTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalShortTermsFacet.ShortEntry>of(), aggregator.missing(), aggregator.total());
        } else {
            if (size < EntryPriorityQueue.LIMIT) {
                EntryPriorityQueue ordered = new EntryPriorityQueue(size, comparatorType.comparator());
                for (TShortIntIterator it = facets.iterator(); it.hasNext(); ) {
                    it.advance();
                    ordered.insertWithOverflow(new InternalShortTermsFacet.ShortEntry(it.key(), it.value()));
                }
                InternalShortTermsFacet.ShortEntry[] list = new InternalShortTermsFacet.ShortEntry[ordered.size()];
                for (int i = ordered.size() - 1; i >= 0; i--) {
                    list[i] = (InternalShortTermsFacet.ShortEntry) ordered.pop();
                }
                CacheRecycler.pushShortIntMap(facets);
                return new InternalShortTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing(), aggregator.total());
            } else {
                BoundedTreeSet<InternalShortTermsFacet.ShortEntry> ordered = new BoundedTreeSet<InternalShortTermsFacet.ShortEntry>(comparatorType.comparator(), size);
                for (TShortIntIterator it = facets.iterator(); it.hasNext(); ) {
                    it.advance();
                    ordered.add(new InternalShortTermsFacet.ShortEntry(it.key(), it.value()));
                }
                CacheRecycler.pushShortIntMap(facets);
                return new InternalShortTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing(), aggregator.total());
View Full Code Here

TOP

Related Classes of org.elasticsearch.common.trove.map.hash.TShortIntHashMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.