Skip to main content

IndexWriter

Struct IndexWriter 

Source
pub struct IndexWriter { /* private fields */ }
Expand description

Writes documents to a Luci index.

Usage:

  1. Create with IndexWriter::new(storage, schema, analyzers)
  2. Call put(doc) for each document
  3. Call commit() to make documents searchable

Implementations§

Source§

impl IndexWriter

Source

pub fn new( storage: impl Storage + 'static, schema: Mapping, analyzers: AnalyzerRegistry, ) -> Self

Create a new IndexWriter.

Source

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]].

Source

pub fn set_analysis_json(&mut self, json: Option<Value>)

Set the analysis settings JSON to persist alongside the mapping.

Source

pub fn load_deletions(&mut self, deletions: DeletionMap)

Load persisted deletions (called on Index::open).

Source

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).

Source

pub fn global_hnsw(&self) -> &GlobalHnsw

Access the global HNSW for serialization on commit and for taking a search-side snapshot via to_bytes.

Source

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).

Source

pub fn deletions(&self) -> &DeletionMap

Get the current deletion map (for search-time filtering).

Source

pub fn set_memory_budget(&mut self, budget: usize)

Set the memory budget for auto-flush.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn buffered_doc_count(&self) -> u32

Number of documents in the current (unflushed) buffer.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool