
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(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.
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.
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.
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.
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.
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.
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.
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.
DeleteDocuments(TermQuery)
Queues a term-based deletion. Documents matching query are deleted
on the next Commit() call.
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.
GetNrtSegments()
Returns all committed and flushed segments for near-real-time search. Flushes any buffered documents first but does not write a commit file.

GetSnapshotProtectedSegments()
Returns the set of segment IDs protected by active snapshots.
InitialiseDwptPool(int)
Initialises the DWPT pool for concurrent indexing. Call once before using AddDocumentLockFree(LeanDocument) or AddDocumentsConcurrent(IReadOnlyList<LeanDocument>).
ReleaseSnapshot(IndexSnapshot)
Releases a previously held snapshot, allowing its segments to be merged away.
UpdateDocument(string, string, LeanDocument)
Atomically deletes documents matching the selector and adds the replacement.