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
impl TextIndex
Sourcepub fn open_or_create(
dir: &Path,
options: &TextIndexOptions,
) -> Result<Self, TextIndexError>
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.
Sourcepub fn check_adoptable(dir: &Path, fingerprint: &str) -> Result<(), String>
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.
Sourcepub fn open_doc_count_read_only(dir: &Path) -> Result<u64, TextIndexError>
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.
Sourcepub fn create_in_ram(options: &TextIndexOptions) -> Result<Self, TextIndexError>
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.
Sourcepub fn add_batch(
&self,
documents: &[TextIndexDoc],
) -> Result<(), TextIndexError>
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.
Sourcepub fn search(
&self,
request: &TextSearchRequest,
) -> Result<Vec<Vec<u8>>, TextIndexError>
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.
Sourcepub fn search_scoped(
&self,
request: &TextSearchRequest,
predicates: &[Vec<u8>],
) -> Result<Vec<Vec<u8>>, TextIndexError>
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.
Sourcepub fn wipe(&self) -> Result<(), TextIndexError>
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.
Sourcepub fn schema(&self) -> &TextSchema
pub fn schema(&self) -> &TextSchema
The schema this index was opened with.
Sourcepub fn seed_chars(&self) -> usize
pub fn seed_chars(&self) -> usize
The seed length the documents were built with.
Sourcepub fn fingerprint(&self) -> &str
pub fn fingerprint(&self) -> &str
The config fingerprint the index was created under.
Sourcepub fn meta(&self) -> Result<TextIndexMeta, TextIndexError>
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.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for TextIndex
impl !RefUnwindSafe for TextIndex
impl Send for TextIndex
impl Sync for TextIndex
impl Unpin for TextIndex
impl UnsafeUnpin for TextIndex
impl !UnwindSafe for TextIndex
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for 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