Skip to main content

SearchEngine

Struct SearchEngine 

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

The full-text search engine backed by Tantivy.

Implementations§

Source§

impl SearchEngine

Source

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

Create or open a search engine index at the given path.

Source

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

Open the index in read-only mode: no writer is created, so no exclusive tantivy lock is taken. Multiple processes (e.g. Antigravity’s proxy and an opencode MCP client) can share the store for searches; writes through this engine fail with a clear error.

Source

pub const fn schema_migrated(&self) -> bool

True when the on-disk index had an incompatible schema and was replaced with a fresh empty index at open time. The old index was preserved as a .schema-mismatch.<timestamp> sibling directory. Callers that own the canonical LMDB store should rebuild via reindex::rebuild_index when this returns true.

Source

pub const fn health(&self) -> &IndexHealth

Returns a snapshot of index health (success/failure counts, degraded flag, last error).

Source

pub fn count_docs_in_galaxy(&self, galaxy: &str) -> Result<usize>

Count the number of indexed documents for a specific galaxy.

Used by consistency checks to compare Tantivy doc counts against LMDB memory counts. Returns 0 if the index is empty or the galaxy has no documents.

Source

pub fn indexed_ids_in_galaxy(&self, galaxy: &str) -> Result<HashSet<String>>

Enumerate the memory IDs currently indexed for one galaxy.

Used by the incremental drift heal to diff the index against LMDB without rebuilding whole galaxies. Bounded by the galaxy’s own document count (a term query on the non-tokenized galaxy field, so the cost is one term seek + one stored-field fetch per hit).

Source

pub fn is_readonly(&self) -> bool

True when the engine was opened read-only (no tantivy writer).

Source

pub fn writer(&self) -> Result<MutexGuard<'_, Option<IndexWriter>>>

Lock the shared writer for adding/removing documents.

The writer is created at open() time and shared across all callers via a Mutex, preventing lock contention with Tantivy’s single-writer model. In read-only mode this errors.

Source

pub fn add_document( &self, writer: &mut Option<IndexWriter>, memory_id: &str, galaxy: &str, content: &str, tags: &[String], timestamp: i64, ) -> Result<()>

Index a memory document.

Content that is not clean text (binary garbage, low printable-char ratio, null bytes) is skipped at index time — no document is added and Ok(()) is returned so callers can proceed. See sanitize_content_for_index.

Source

pub fn delete_document( &self, writer: &mut Option<IndexWriter>, memory_id: &str, ) -> Result<()>

Delete documents by memory ID.

Source

pub fn delete_by_galaxy( &self, writer: &mut Option<IndexWriter>, galaxy: &str, ) -> Result<()>

Delete every document belonging to a galaxy.

Used by filtered reindexing so --galaxy codex removes only codex documents instead of wiping the entire index.

Source

pub fn commit(&self, writer: &mut Option<IndexWriter>) -> Result<()>

Commit pending index changes and reload the reader.

Source

pub fn search(&self, query: &str, limit: usize) -> Result<Vec<SearchResult>>

Search for memories matching the query text. Returns results sorted by BM25 score (descending).

The query is stripped of stopwords and sanitized to prevent Tantivy query syntax injection.

Source

pub fn search_in_galaxy( &self, query: &str, galaxy: Option<Galaxy>, limit: usize, ) -> Result<Vec<SearchResult>>

Search for memories matching the query, optionally filtered by galaxy.

The query is stripped of stopwords and sanitized to escape Tantivy special characters (+, -, *, “”, field syntax, boolean operators) that could be used for query injection.

Source

pub fn search_opt( &self, query: &str, opts: &SearchOptions, ) -> Result<Vec<SearchResult>>

Search with full recall-quality options (stopword stripping, score thresholds, token-coverage filtering, galaxy filter).

Pipeline:

  1. strip_stopwords — common English stopwords are removed.
  2. sanitize_tantivy_query — reserved query syntax is neutralized; plain terms (incl. hyphenated compounds) pass through so the tokenizer can split them into phrase matches.
  3. OR query across content + tags (broader recall than conjunction, filtered by token-coverage in step 5).
  4. Hits below min_score (absolute) or relative_floor * top_score are dropped.
  5. Token-coverage floor: for queries with ≥ 3 terms, at least 2 must appear in the content (stemming-aware). Documents that pass the floor receive a coverage-ratio score boost.
  6. Output content is scrubbed of control characters.
Source

pub fn search_ids(&self, query: &str, limit: usize) -> Result<Vec<MemoryId>>

Search and return memory IDs only (for integration with MemoryStore).

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

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

Source§

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

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

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

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

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

Source§

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

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

Source§

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

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> Fruit for T
where T: Send + Downcast,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more