Skip to main content

TextIndex

Struct TextIndex 

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

A text index directory, or an in-memory index in tests and the memory backend.

Implementations§

Source§

impl TextIndex

Source

pub fn open_or_create( dir: &Path, options: &TextIndexOptions, ) -> Result<Self, TextIndexError>

Open the index at dir, creating it when the directory holds no index yet.

A directory that already holds one is authoritative: its stored schema and sidecar decide the analyzer and seed length, so reopening never has to reconstruct them from configuration. options is used only when the directory is empty. A directory that is not ours (wrong fields, wrong field types) is an error rather than a silent mismatch.

Source

pub fn check_adoptable(dir: &Path, fingerprint: &str) -> Result<(), String>

Whether the index at dir can be adopted by a build configured with fingerprint.

Read-only and lock-free: reads the Tantivy meta and the sidecar, never creates a directory, opens a writer, or rebuilds. Ok(()) when dir holds no index (a fresh store, which the normal build path covers) or when the stored schema and fingerprint both match. A mismatch returns a human-readable reason; the caller turns it into a fail-fast error, because this build never rebuilds an existing index automatically — its documents precede every axis write, so a schema mismatch later fails every insert, not just text:query.

Source

pub fn open_doc_count_read_only(dir: &Path) -> Result<u64, TextIndexError>

Live document count of an on-disk index, WITHOUT taking the writer lock or creating anything: opens the committed segments read-only, so waratah text status can inspect a directory without contending with a live cluster’s writer and without materializing an index in a directory that has no Tantivy meta yet. Errors when the directory holds no index.

Source

pub fn create_in_ram(options: &TextIndexOptions) -> Result<Self, TextIndexError>

An in-memory index. Used by the memory storage backend and by tests; the documents vanish with the process, exactly like the store they mirror.

Source

pub fn add_batch( &self, documents: &[TextIndexDoc], ) -> Result<(), TextIndexError>

Append one batch and publish it.

add_document → commit → IndexReader::reload before returning. An empty batch is a no-op: no commit, no reload.

Source

pub fn search( &self, request: &TextSearchRequest, ) -> Result<Vec<Vec<u8>>, TextIndexError>

Drain one candidate request into distinct encoded terms.

The returned list is deduplicated by term bytes and sorted in ascending encoded-term-byte order — the same byte order as the hexastore’s object key prefix. A consumer that walks one OPSG prefix per literal therefore seeks in ascending key order, which keeps the walk deterministic and avoids backtracking in the block cache; the walks are still one prefix seek per literal, not a shared cursor. Unlike the scan RPCs this is not a cursor: calling again restarts the drain with an identical result for the same index state.

The drain is UNBOUNDED in v1: every minted request carries limit: 0 (no caller arms the guard), so the whole distinct candidate set materializes in one partition-side allocation — a broad FTS query over a large vocabulary pays for it here. The CandidateLimitExceeded arm below is therefore unreachable in v1; it exists so arming a limit later is a one-line change, not a new error path.

Source

pub fn search_scoped( &self, request: &TextSearchRequest, predicates: &[Vec<u8>], ) -> Result<Vec<Vec<u8>>, TextIndexError>

Self::search restricted to documents whose stored predicate is in predicates (the encoded predicate bytes a document carries).

An empty slice is no filter. The subject resolve passes the request’s whole predicate set in one call — the drain then returns each matching literal once, and the OPSG walk (which uses the same set) resolves it under every named predicate.

Source

pub fn wipe(&self) -> Result<(), TextIndexError>

Remove every document, keeping the configuration and clearing trust.

Trust is cleared FIRST — the sidecar is rewritten with no epoch and fsynced before any document is deleted — so every crash point leaves a consistent on-disk state: either the old (complete) index under its stamped epoch, or any document state under a cleared epoch. The forbidden state — an empty index that still reads trusted — is unreachable, and the next start rebuilds from the cleared epoch.

Used by the startup build, which runs before anything serves and can therefore safely start from an empty index. A build that runs while serving must be additive instead: an in-progress write’s document may be committed while its row is not yet visible to the walk.

Source

pub fn doc_count(&self) -> u64

Number of live documents (one per indexed literal).

Source

pub fn schema(&self) -> &TextSchema

The schema this index was opened with.

Source

pub fn analyzer(&self) -> &str

The analyzer this index analyses text with.

Source

pub fn seed_chars(&self) -> usize

The seed length the documents were built with.

Source

pub fn fingerprint(&self) -> &str

The config fingerprint the index was created under.

Source

pub fn dir(&self) -> Option<&Path>

The directory, None for an in-memory index.

Source

pub fn meta(&self) -> Result<TextIndexMeta, TextIndexError>

The index metadata, including the build epoch (None = not built).

Held in memory so the RAM backend can report a stamped epoch exactly like the disk backend; on disk it mirrors the sidecar.

Source

pub fn stamp(&self, epoch: u64) -> Result<(), TextIndexError>

Stamp the index as built up to epoch.

Trait Implementations§

Source§

impl Debug for TextIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

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

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Fruit for T
where T: Send + Downcast,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,