PostingsEnum
- Namespace
- Rowles.LeanCorpus.Codecs.Postings
- Assembly
- Rowles.LeanCorpus.dll
Forward-only cursor over a postings list. Decodes doc IDs and frequencies once into ArrayPool-rented buffers, then yields (DocId, Freq) pairs via MoveNext(). Optionally decodes positions when created via CreateWithPositions(IndexInput, long).
Lifetime contract: When using the lazy position path, this struct holds a raw
byte* pointer into a memory-mapped IndexInput. The cursor retains the
input mapping until the cursor is disposed, so disposing the source input or its owning
searcher waits for active cursor operations to finish.
public struct PostingsEnum : IDisposable
- Implements
DocFreq
Gets the total number of documents in this postings list.
DocId
Gets the current document ID, or -1 if the cursor has not been advanced or is exhausted.
Empty
A pre-built empty postings enum that is immediately exhausted.
Freq
IsExhausted
Gets a value indicating whether the cursor has passed the last document.
Advance(int)
Advances to the first document >= targetDocId. Returns true if found. Lazy mode delegates to BlockPostingsEnum skip data for O(log N) seeking. Eager mode uses binary search on the pre-decoded docId array.
Create(IndexInput, long)
Creates a PostingsEnum by reading from a memory-mapped IndexInput at the specified offset.
CreateWithPositions(IndexInput, long)
Creates a PostingsEnum that lazily decodes position data for phrase queries. During creation, only per-doc byte offsets and position counts are recorded. Actual position values are decoded on-demand via GetCurrentPositions().
Dispose()
Returns all rented buffers back to ArrayPool<T>.
GetCurrentPositions()
Returns positions for the current document. Supports both eager (pre-decoded) and lazy (on-demand) position data. Returns empty span if positions were not available. Caches the last decoded result to avoid redundant VarInt decoding when called multiple times for the same document (common in phrase evaluation).
GetPayload(int)
Gets the payload for a specific position index of the current document. Requires GetCurrentPositions() to have been called first on this document to populate payload offsets. Returns empty span when no payloads are stored.
MoveNext()
Advances the cursor to the next document. Returns true if a document was found.
MoveNext(out int, out int)
Advances the cursor and returns the current document ID and frequency.
Reset()
ValidateFileHeader(IndexInput)
Validates the postings file header. Returns the format version. Should be called when opening a segment, before using Create/CreateWithPositions.