org.apache.lucene.codecs.lucene50

## Class Lucene50PostingsWriter

- java.lang.Object
- - org.apache.lucene.codecs.PostingsWriterBase
  - - org.apache.lucene.codecs.PushPostingsWriterBase
    - - org.apache.lucene.codecs.lucene50.Lucene50PostingsWriter

All Implemented Interfaces:
  Closeable, AutoCloseable

    public final class Lucene50PostingsWriter
    extends PushPostingsWriterBase

Concrete class that writes docId(maybe frq,pos,offset,payloads) list with postings format. Postings list for each term will be stored separately.

See Also:
  `for details about skipping setting and postings layout.`
WARNING: This API is experimental and might change in incompatible ways in the next release.

### Field Summary

### Fields inherited from class org.apache.lucene.codecs.PushPostingsWriterBase

`fieldInfo, indexOptions, writeFreqs, writeOffsets, writePayloads, writePositions`

### Constructor Summary

Constructors
Constructor and Description
`Lucene50PostingsWriter(SegmentWriteState state)` Creates a postings writer

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addPosition(int position, BytesRef payload, int startOffset, int endOffset)` Add a new position and payload, and start/end offset.
`void` `close()`
`void` `encodeTerm(long[] longs, DataOutput out, FieldInfo fieldInfo, BlockTermState _state, boolean absolute)` Encode metadata as long[] and byte[].
`void` `finishDoc()` Called when we are done adding positions and payloads for each doc.
`void` `finishTerm(BlockTermState _state)` Called when we are done adding docs to this term
`void` `init(IndexOutput termsOut, SegmentWriteState state)` Called once after startup, before any terms have been added.
`org.apache.lucene.codecs.lucene50.Lucene50PostingsFormat.IntBlockTermState` `newTermState()` Return a newly created empty TermState
`int` `setField(FieldInfo fieldInfo)` Sets the current field for writing, and returns the fixed length of long[] metadata (which is fixed per field), called when the writing switches to another field.
`void` `startDoc(int docID, int termDocFreq)` Adds a new doc in this term.
`void` `startTerm()` Start a new term.

### Methods inherited from class org.apache.lucene.codecs.PushPostingsWriterBase

`writeTerm`

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

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

### Constructor Detail

#### Lucene50PostingsWriter

    public Lucene50PostingsWriter(SegmentWriteState state)
                           throws IOException

Creates a postings writer

Throws:
  `IOException`

### Method Detail

#### newTermState

    public org.apache.lucene.codecs.lucene50.Lucene50PostingsFormat.IntBlockTermState newTermState()

Description copied from class: `PushPostingsWriterBase`
Return a newly created empty TermState

Specified by:
  `newTermState` in class `PushPostingsWriterBase`

#### init

    public void init(IndexOutput termsOut,
                     SegmentWriteState state)
              throws IOException

Description copied from class: `PostingsWriterBase`
Called once after startup, before any terms have been added. Implementations typically write a header to the provided `termsOut`.

Specified by:
  `init` in class `PostingsWriterBase`
Throws:
  `IOException`

#### setField

    public int setField(FieldInfo fieldInfo)

Description copied from class: `PushPostingsWriterBase`
Sets the current field for writing, and returns the fixed length of long[] metadata (which is fixed per field), called when the writing switches to another field.

Overrides:
  `setField` in class `PushPostingsWriterBase`

#### startTerm

    public void startTerm()

Description copied from class: `PushPostingsWriterBase`
Start a new term. Note that a matching call to `PushPostingsWriterBase.finishTerm(BlockTermState)` is done, only if the term has at least one document.

Specified by:
  `startTerm` in class `PushPostingsWriterBase`

#### startDoc

    public void startDoc(int docID,
                         int termDocFreq)
                  throws IOException

Description copied from class: `PushPostingsWriterBase`
Adds a new doc in this term. `freq` will be -1 when term frequencies are omitted for the field.

Specified by:
  `startDoc` in class `PushPostingsWriterBase`
Throws:
  `IOException`

#### addPosition

    public void addPosition(int position,
                            BytesRef payload,
                            int startOffset,
                            int endOffset)
                     throws IOException

Description copied from class: `PushPostingsWriterBase`
Add a new position and payload, and start/end offset. A null payload means no payload; a non-null payload with zero length also means no payload. Caller may reuse the `BytesRef` for the payload between calls (method must fully consume the payload). `startOffset` and `endOffset` will be -1 when offsets are not indexed.

Specified by:
  `addPosition` in class `PushPostingsWriterBase`
Throws:
  `IOException`

#### finishDoc

    public void finishDoc()
                   throws IOException

Description copied from class: `PushPostingsWriterBase`
Called when we are done adding positions and payloads for each doc.

Specified by:
  `finishDoc` in class `PushPostingsWriterBase`
Throws:
  `IOException`

#### finishTerm

    public void finishTerm(BlockTermState _state)
                    throws IOException

Called when we are done adding docs to this term

Specified by:
  `finishTerm` in class `PushPostingsWriterBase`
Throws:
  `IOException`

#### encodeTerm

    public void encodeTerm(long[] longs,
                           DataOutput out,
                           FieldInfo fieldInfo,
                           BlockTermState _state,
                           boolean absolute)
                    throws IOException

Description copied from class: `PostingsWriterBase`
Encode metadata as long[] and byte[]. `absolute` controls whether current term is delta encoded according to latest term. Usually elements in `longs` are file pointers, so each one always increases when a new term is consumed. `out` is used to write generic bytes, which are not monotonic. NOTE: sometimes long[] might contain "don't care" values that are unused, e.g. the pointer to postings list may not be defined for some terms but is defined for others, if it is designed to inline some postings data in term dictionary. In this case, the postings writer should always use the last value, so that each element in metadata long[] remains monotonic.

Specified by:
  `encodeTerm` in class `PostingsWriterBase`
Throws:
  `IOException`

#### close

    public void close()
               throws IOException

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in class `PostingsWriterBase`
Throws:
  `IOException`