Skip to main content

Index

Struct Index 

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

A Luci search index.

Provides a unified API for indexing and searching JSON documents. Owns the storage, schema, writer, and search state.

Implementations§

Source§

impl Index

Source

pub fn create(path: impl AsRef<Path>) -> Result<Self>

Create a new index at the given path with fully dynamic mappings.

All field types are inferred from the first document that contains each field. Mappings are persisted to disk on commit.

Source

pub fn create_with_mapping( path: impl AsRef<Path>, mapping: Mapping, ) -> Result<Self>

Create a new index with explicit field mappings.

Unknown fields are handled according to the mapping’s dynamic mode (default: true, meaning auto-map and index).

Source

pub fn create_with_settings( path: impl AsRef<Path>, mapping: Mapping, analysis_config: Option<AnalysisConfig>, ) -> Result<Self>

Create a new index with explicit mappings and analysis settings.

The analysis_config defines custom analyzers, tokenizers, char filters, and token filters. It is persisted in the index metadata so that open can rebuild the analyzer registry.

See [[feature-analysis-pipeline]].

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Open an existing index at the given path.

Mappings are loaded from disk (persisted on each commit). If the index has no persisted mappings (pre-persistence format), an empty mapping with dynamic=true is used.

Source

pub fn add(&self, doc: Value) -> Result<()>

Add a document. Auto-commits — the document is immediately searchable.

Blocks if a transaction is active (waits for it to complete). See [[architecture-concurrency-transactions]].

Source

pub fn bulk(&self, docs: Vec<Value>) -> Result<Value>

Add multiple documents in a single call. Auto-commits at the end — all documents are searchable after this returns.

Blocks if a transaction is active (waits for it to complete). Reduces Python→Rust FFI overhead from one call per document to one call per batch. Fails fast on the first invalid document.

Returns {"took": <ms>, "count": <n>}.

See [[feature-bulk-api]].

Source

pub fn get(&self, id: &str) -> Result<Option<Value>>

Get a document by its _id. Returns the source if found. See [[feature-document-crud]].

Source

pub fn delete(&self, id: &str) -> Result<bool>

Delete a document by its _id. Returns true if found and deleted. See [[feature-document-crud]].

Source

pub fn update(&self, id: &str, partial_doc: Value) -> Result<bool>

Update a document by its _id with a partial doc merge. Returns true if found and updated. See [[feature-document-crud]].

Source

pub fn delete_by_query(&self, query: Value) -> Result<u64>

Delete all documents matching a query. Returns count deleted. See [[feature-document-crud]].

Source

pub fn count(&self, query: Value) -> Result<u64>

Count documents matching a query. See [[feature-document-crud]].

Source

pub fn force_merge(&self, max_segments: usize) -> Result<()>

Force-merge all segments down to at most max_segments.

Call after bulk indexing is complete to optimize for query performance. Invalidates the cached searcher.

Source

pub fn search(&self, expr: &SearchExpression) -> Result<SearchResults>

Search the index with a native SearchExpression.

Thin entry point: refreshes the reader, delegates to Searcher::execute_query, then handles deletion filtering and total_hits capping.

Source

pub fn set_memory_budget(&self, budget: usize)

Set the memory budget for auto-flush (bytes).

When the in-memory buffer exceeds this size, it is automatically flushed to a new segment. Smaller values produce more segments (better parallelism, more merge work). Default: 64 MB.

Source

pub fn set_write_timeout(&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. Not persisted — applies only to this session.

Source

pub fn schema(&self) -> &Mapping

Get the schema.

Source

pub fn buffered_doc_count(&self) -> u32

Number of buffered (uncommitted) documents.

Source

pub fn begin_transaction(&self) -> Result<()>

Begin a transaction. Blocks if another transaction is active.

While a transaction is active, add() and bulk() will block until the transaction completes.

Source

pub fn end_transaction(&self)

End a transaction, waking any blocked writers.

Must only be called after a successful begin_transaction().

Source

pub fn is_transaction_active(&self) -> bool

Whether a transaction is currently active.

Source

pub fn txn_add(&self, doc: Value) -> Result<()>

Add a document without committing. For use inside a transaction.

The caller must have called begin_transaction() first.

Source

pub fn txn_commit(&self) -> Result<()>

Commit all buffered documents. For use inside a transaction.

The caller must have called begin_transaction() first.

Source

pub fn txn_rollback(&self)

Discard all buffered (uncommitted) documents. For transaction rollback.

Resets the writer’s in-memory buffer without flushing to storage.

Auto Trait Implementations§

§

impl !Freeze for Index

§

impl RefUnwindSafe for Index

§

impl Send for Index

§

impl Sync for Index

§

impl Unpin for Index

§

impl UnsafeUnpin for Index

§

impl UnwindSafe for Index

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