org.apache.lucene.codecs

## Class TermsConsumer

- java.lang.Object
- - org.apache.lucene.codecs.TermsConsumer

    public abstract class TermsConsumer
    extends Object

Abstract API that consumes terms for an individual field.

The lifecycle is:

1. TermsConsumer is returned for each field by `FieldsConsumer.addField(FieldInfo)`.
2. TermsConsumer returns a `PostingsConsumer` for each term in `startTerm(BytesRef)`.
3. When the producer (e.g. IndexWriter) is done adding documents for the term, it calls `finishTerm(BytesRef, TermStats)`, passing in the accumulated term statistics.
4. Producer calls `finish(long, long, int)` with the accumulated collection statistics when it is finished adding terms to the field.

WARNING: This API is experimental and might change in incompatible ways in the next release.

### Constructor Summary

Constructors
`protected` `TermsConsumer()` Sole constructor.

### Method Summary

Methods
`abstract void` `finish(long sumTotalTermFreq, long sumDocFreq, int docCount)` Called when we are done adding terms to this field.
`abstract void` `finishTerm(BytesRef text, TermStats stats)` Finishes the current term; numDocs must be > 0.
`abstract Comparator<BytesRef>` `getComparator()` Return the BytesRef Comparator used to sort terms before feeding to this API.
`void` `merge(MergeState mergeState, FieldInfo.IndexOptions indexOptions, TermsEnum termsEnum)` Default merge impl
`abstract PostingsConsumer` `startTerm(BytesRef text)` Starts a new term in this field; this may be called with no corresponding call to finish if the term had no docs.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### TermsConsumer

    protected TermsConsumer()

Sole constructor. (For invocation by subclass constructors, typically implicit.)

### Method Detail

#### startTerm

    public abstract PostingsConsumer startTerm(BytesRef text)
                                        throws IOException

Starts a new term in this field; this may be called with no corresponding call to finish if the term had no docs.

Throws:
  `IOException`

#### finishTerm

    public abstract void finishTerm(BytesRef text,
                  TermStats stats)
                             throws IOException

Finishes the current term; numDocs must be > 0. `stats.totalTermFreq` will be -1 when term frequencies are omitted for the field.

Throws:
  `IOException`

#### finish

    public abstract void finish(long sumTotalTermFreq,
              long sumDocFreq,
              int docCount)
                         throws IOException

Called when we are done adding terms to this field. `sumTotalTermFreq` will be -1 when term frequencies are omitted for the field.

Throws:
  `IOException`

#### getComparator

    public abstract Comparator<BytesRef> getComparator()
                                                throws IOException

Return the BytesRef Comparator used to sort terms before feeding to this API.

Throws:
  `IOException`

#### merge

    public void merge(MergeState mergeState,
             FieldInfo.IndexOptions indexOptions,
             TermsEnum termsEnum)
               throws IOException

Default merge impl

Throws:
  `IOException`