pub struct IndexWriter { /* private fields */ }Expand description
Writes documents to a Luci index.
Usage:
- Create with
IndexWriter::new(storage, schema, analyzers) - Call
put(doc)for each document - Call
commit()to make documents searchable
Implementations§
Source§impl IndexWriter
impl IndexWriter
Sourcepub fn new(
storage: impl Storage + 'static,
schema: Mapping,
analyzers: AnalyzerRegistry,
) -> Self
pub fn new( storage: impl Storage + 'static, schema: Mapping, analyzers: AnalyzerRegistry, ) -> Self
Create a new IndexWriter.
Sourcepub fn set_build_threads(&mut self, threads: BuildThreads)
pub fn set_build_threads(&mut self, threads: BuildThreads)
Override the thread budget for the commit-time HNSW connect phase.
Production leaves the Ambient default (rayon global pool);
deterministic Rust tests/profile harnesses set Fixed(1) to get a
bit-identical graph independent of the ambient pool size. Not
exposed to the Python API. See [[optimization-concurrent-hnsw-insert]].
Sourcepub fn set_analysis_json(&mut self, json: Option<Value>)
pub fn set_analysis_json(&mut self, json: Option<Value>)
Set the analysis settings JSON to persist alongside the mapping.
Sourcepub fn load_deletions(&mut self, deletions: DeletionMap)
pub fn load_deletions(&mut self, deletions: DeletionMap)
Load persisted deletions (called on Index::open).
Sourcepub fn load_global_hnsw(&mut self, global_hnsw: GlobalHnsw)
pub fn load_global_hnsw(&mut self, global_hnsw: GlobalHnsw)
Replace the in-memory global HNSW with one deserialized from
persisted bytes (called on Index::open).
Sourcepub fn global_hnsw(&self) -> &GlobalHnsw
pub fn global_hnsw(&self) -> &GlobalHnsw
Access the global HNSW for serialization on commit and for
taking a search-side snapshot via to_bytes.
Sourcepub fn mark_deleted(&mut self, segment_id: SegmentId, doc_id: DocId)
pub fn mark_deleted(&mut self, segment_id: SegmentId, doc_id: DocId)
Mark a document as deleted. Takes effect on next search (no commit needed).
Sourcepub fn deletions(&self) -> &DeletionMap
pub fn deletions(&self) -> &DeletionMap
Get the current deletion map (for search-time filtering).
Sourcepub fn set_memory_budget(&mut self, budget: usize)
pub fn set_memory_budget(&mut self, budget: usize)
Set the memory budget for auto-flush.
Sourcepub fn set_write_timeout(&mut self, timeout: Duration)
pub fn set_write_timeout(&mut self, timeout: Duration)
Set the timeout for acquiring the cross-process write lock.
Default: 5 seconds. If another process holds the write lock,
retries until the timeout, then returns WriterLocked.
Sourcepub fn add(&mut self, doc: Value) -> Result<()>
pub fn add(&mut self, doc: Value) -> Result<()>
Add a JSON document to the index.
The document is validated against the schema, text fields are analyzed,
and the result is buffered. Call commit() to make it searchable.
Sourcepub fn commit(&mut self) -> Result<()>
pub fn commit(&mut self) -> Result<()>
Flush the buffer and commit all pending segments to storage.
Persists the current field mappings alongside segment metadata.
After commit returns, all documents added via add() are searchable.
If the merge policy triggers, a synchronous merge is executed before
returning.
Sourcepub fn force_merge(&mut self, max_segments: usize) -> Result<()>
pub fn force_merge(&mut self, max_segments: usize) -> Result<()>
Force-merge all segments down to at most max_segments.
Repeatedly merges until the segment count is at or below the target. This is expensive and should only be called after bulk indexing is complete, not during normal operation.
Sourcepub fn buffered_doc_count(&self) -> u32
pub fn buffered_doc_count(&self) -> u32
Number of documents in the current (unflushed) buffer.
Sourcepub fn discard_buffer(&mut self)
pub fn discard_buffer(&mut self)
Discard the in-memory segment buffer without flushing to storage.
Used for transaction rollback. Resets the builder to an empty state.
Auto Trait Implementations§
impl !Freeze for IndexWriter
impl !RefUnwindSafe for IndexWriter
impl !Sync for IndexWriter
impl !UnwindSafe for IndexWriter
impl Send for IndexWriter
impl Unpin for IndexWriter
impl UnsafeUnpin for IndexWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more