code: public NumericTermsSet collect(HitStream hitStream) throws IOException {
      hitStream.initialize(); // initialise the stream
      int nHits = hitStream.getHits();
      NumericTermsSet terms = this.newTermsSet(this.expectedTerms != -1 ? this.expectedTerms : nHits, breaker);
      try {
        NumericTermStream reusableTermStream = NumericTermStream.get(context.searcher().getIndexReader(), indexFieldData);
  
        while (terms.size() < this.maxTerms && hitStream.hasNext()) {
          hitStream.next();
          reusableTermStream = hitStream.getTermStream(reusableTermStream);
  
          while (terms.size() < this.maxTerms && reusableTermStream.hasNext()) {
            terms.add(reusableTermStream.next());
          }
        }
  
        boolean isPruned = hitStream.getTotalHits() > hitStream.getHits();
        isPruned |= this.maxTerms < nHits;
        terms.setIsPruned(isPruned);
        return terms;
      }
      catch (Throwable t) {
        // If something happens during the term collection, release the terms set and adjust the circuit breaker
        terms.release();
        throw t;
      }
    }
docs: Collects the terms into a {@link LongHashSet}.