Table of Contents

Public classSealed IndexWriter

Namespace
Rowles.LeanLucene.Index.Indexer
Assembly
Rowles.LeanLucene.dll

Accepts documents, analyses text fields, buffers in memory, and flushes immutable segments to disk.

public sealed class IndexWriter : IDisposable
IndexWriter

Public constructor IndexWriter(MMapDirectory, IndexWriterConfig)

Initialises a new IndexWriter for the given directory with the specified configuration. Acquires an exclusive write lock on the directory. Only one writer may be open per directory at a time.

Public method AddDocument(LeanDocument)

Indexes a single document. Validates the document against the schema if one is configured. May block if MaxQueuedDocs backpressure is enabled. Automatically flushes a segment when the RAM or document count threshold is reached.

Public method AddDocumentBlock(IReadOnlyList<LeanDocument>)

Indexes a block of child documents followed by a parent document atomically. The last document in block is the parent; all preceding documents are children. Children are stored contiguously before their parent in the segment, enabling block-join queries.

Public method AddDocumentLockFree(LeanDocument)

Lock-free document addition using per-thread DWPT buffers. Uses System.Threading.Interlocked.Increment(System.Int32@) for round-robin DWPT selection. Each DWPT flushes independently when its RAM threshold is reached. Call InitialiseDwptPool(int) before first use.

Public method AddDocuments(IReadOnlyList<LeanDocument>)

Indexes a batch of documents with a single lock acquisition. Faster than calling AddDocument(LeanDocument) in a loop because lock and backpressure overhead is paid once for the entire batch.

Public method AddDocumentsConcurrent(IReadOnlyList<LeanDocument>)

Indexes a batch of documents using parallel per-thread writer buffers (DWPT). Partitions the input across all available processors and merges results into the main buffer under a single lock acquisition per DWPT.

Public method Commit()

Flushes all buffered documents and pending deletions to disk, writes a new segments_N commit file, and applies the configured deletion policy. Schedules a background merge after the flush.

Public method CreateSnapshot()

Creates a point-in-time snapshot of the currently committed segments. While held, segments referenced by the snapshot will not be deleted during merge. Call ReleaseSnapshot(IndexSnapshot) when the snapshot is no longer needed.

Public method DeleteDocuments(TermQuery)

Queues a term-based deletion. Documents matching query are deleted on the next Commit() call.

Public method Dispose()

Releases all resources held by this writer, including the directory write lock. Cancels any background merge task and waits for in-progress merge I/O to complete.

Public method GetNrtSegments()

Returns all committed and flushed segments for near-real-time search. Flushes any buffered documents first but does not write a commit file.

Internal methodInternal GetSnapshotProtectedSegments()

Returns the set of segment IDs protected by active snapshots.

Public method InitialiseDwptPool(int)

Initialises the DWPT pool for concurrent indexing. Call once before using AddDocumentLockFree(LeanDocument) or AddDocumentsConcurrent(IReadOnlyList<LeanDocument>).

Public method ReleaseSnapshot(IndexSnapshot)

Releases a previously held snapshot, allowing its segments to be merged away.

Public method UpdateDocument(string, string, LeanDocument)

Atomically deletes documents matching the selector and adds the replacement.