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
impl Index
Sourcepub fn create(path: impl AsRef<Path>) -> Result<Self>
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.
Sourcepub fn create_with_mapping(
path: impl AsRef<Path>,
mapping: Mapping,
) -> Result<Self>
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).
Sourcepub fn create_with_settings(
path: impl AsRef<Path>,
mapping: Mapping,
analysis_config: Option<AnalysisConfig>,
) -> Result<Self>
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]].
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
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.
Sourcepub fn add(&self, doc: Value) -> Result<()>
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]].
Sourcepub fn bulk(&self, docs: Vec<Value>) -> Result<Value>
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]].
Sourcepub fn get(&self, id: &str) -> Result<Option<Value>>
pub fn get(&self, id: &str) -> Result<Option<Value>>
Get a document by its _id. Returns the source if found.
See [[feature-document-crud]].
Sourcepub fn delete(&self, id: &str) -> Result<bool>
pub fn delete(&self, id: &str) -> Result<bool>
Delete a document by its _id. Returns true if found and deleted.
See [[feature-document-crud]].
Sourcepub fn update(&self, id: &str, partial_doc: Value) -> Result<bool>
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]].
Sourcepub fn delete_by_query(&self, query: Value) -> Result<u64>
pub fn delete_by_query(&self, query: Value) -> Result<u64>
Delete all documents matching a query. Returns count deleted. See [[feature-document-crud]].
Sourcepub fn count(&self, query: Value) -> Result<u64>
pub fn count(&self, query: Value) -> Result<u64>
Count documents matching a query. See [[feature-document-crud]].
Sourcepub fn force_merge(&self, max_segments: usize) -> Result<()>
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.
Sourcepub fn search(&self, expr: &SearchExpression) -> Result<SearchResults>
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.
Sourcepub fn set_memory_budget(&self, budget: usize)
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.
Sourcepub fn set_write_timeout(&self, timeout: Duration)
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.
Sourcepub fn buffered_doc_count(&self) -> u32
pub fn buffered_doc_count(&self) -> u32
Number of buffered (uncommitted) documents.
Sourcepub fn begin_transaction(&self) -> Result<()>
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.
Sourcepub fn end_transaction(&self)
pub fn end_transaction(&self)
End a transaction, waking any blocked writers.
Must only be called after a successful begin_transaction().
Sourcepub fn is_transaction_active(&self) -> bool
pub fn is_transaction_active(&self) -> bool
Whether a transaction is currently active.
Sourcepub fn txn_add(&self, doc: Value) -> Result<()>
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.
Sourcepub fn txn_commit(&self) -> Result<()>
pub fn txn_commit(&self) -> Result<()>
Commit all buffered documents. For use inside a transaction.
The caller must have called begin_transaction() first.
Sourcepub fn txn_rollback(&self)
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> 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