public TermsLongFacetExecutor(
      IndexNumericFieldData indexFieldData,
      int size,
      int shardSize,
      TermsFacet.ComparatorType comparatorType,
      boolean allTerms,
      SearchContext context,
      ImmutableSet<BytesRef> excluded,
      SearchScript script,
      CacheRecycler cacheRecycler) {
    this.indexFieldData = indexFieldData;
    this.size = size;
    this.shardSize = shardSize;
    this.comparatorType = comparatorType;
    this.script = script;
    this.excluded = excluded;
    this.facets = cacheRecycler.longIntMap(-1);

    if (allTerms) {
      for (AtomicReaderContext readerContext : context.searcher().getTopReaderContext().leaves()) {
        int maxDoc = readerContext.reader().maxDoc();
        LongValues values = indexFieldData.load(readerContext).getLongValues();
        for (int docId = 0; docId < maxDoc; docId++) {
          final int numValues = values.setDocument(docId);
          final LongIntOpenHashMap v = facets.v();
          for (int i = 0; i < numValues; i++) {
            v.putIfAbsent(values.nextValue(), 0);
          }
        }
      }
    }
  }
 public void onDoc(int docId, LongValues values) {
   final int numValues = values.setDocument(docId);
   int tempMissing = 1;
   for (int i = 0; i < numValues; i++) {
     tempMissing = 0;
     onValue(docId, values.nextValue());
     total++;
   }
   missing += tempMissing;
 }
  @Override
  public void collect(int doc, long owningBucketOrdinal) throws IOException {
    assert owningBucketOrdinal == 0;
    final int valuesCount = values.setDocument(doc);

    long previousKey = Long.MIN_VALUE;
    for (int i = 0; i < valuesCount; ++i) {
      long value = values.nextValue();
      long key = rounding.roundKey(value);
      assert key >= previousKey;
      if (key == previousKey) {
        continue;
      }
      long bucketOrd = bucketOrds.add(key);
      if (bucketOrd < 0) { // already seen
        bucketOrd = -1 - bucketOrd;
      }
      collectBucket(doc, bucketOrd);
      previousKey = key;
    }
  }