コード例 #1
0
  @Override
  public Facet reduce(String name, List<Facet> facets) {
    if (facets.size() == 1) {
      return facets.get(0);
    }
    InternalIntTermsFacet first = (InternalIntTermsFacet) facets.get(0);
    TIntIntHashMap aggregated = aggregateCache.get().get();
    aggregated.clear();
    long missing = 0;

    for (Facet facet : facets) {
      InternalIntTermsFacet mFacet = (InternalIntTermsFacet) facet;
      missing += mFacet.missingCount();
      for (IntEntry entry : mFacet.entries) {
        aggregated.adjustOrPutValue(entry.term, entry.count(), entry.count());
      }
    }

    BoundedTreeSet<IntEntry> ordered =
        new BoundedTreeSet<IntEntry>(first.comparatorType.comparator(), first.requiredSize);
    for (TIntIntIterator it = aggregated.iterator(); it.hasNext(); ) {
      it.advance();
      ordered.add(new IntEntry(it.key(), it.value()));
    }
    first.entries = ordered;
    first.missing = missing;
    return first;
  }
コード例 #2
0
 public static InternalIntTermsFacet readTermsFacet(StreamInput in) throws IOException {
   InternalIntTermsFacet facet = new InternalIntTermsFacet();
   facet.readFrom(in);
   return facet;
 }