Skip to main content

TrigramIndex

Struct TrigramIndex 

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

The trigram inverted index: maps each trigram to the set of node indices that contain it.

Built once at GroundIndex::build time. Query-side: for each query term, extract its trigrams, intersect posting lists → candidate set. The candidate set is a superset of the actual matches (trigrams are necessary but not sufficient); the final contains() check in the scoring loop filters false positives.

As of D0.6 the indexing side is dormant: GroundIndex::build no longer constructs one (scoring.rs:48-50 commented out the call site — see Sprint D0.6). Default::default() gives an empty index for callers that need one; build() is preserved for the D3 re-enable and unit tests that round-trip the original behavior. candidates() is therefore safe to call only against a populated index; today the scoring loop in ground_scoped (retrieval.rs:835-841) bypasses it and falls through to the full scan.

Implementations§

Source§

impl TrigramIndex

Source

pub fn build(haystacks: &[String]) -> Self

Build the index from the per-node haystacks.

Source

pub fn candidates_for_term(&self, term: &str) -> Option<Vec<usize>>

Find candidate node indices for a query term.

Returns the set of nodes whose haystack CONTAINS all trigrams of term. This is a superset of nodes whose haystack contains(term) — the scoring loop does the final contains() check.

For terms shorter than 3 characters (no trigrams), returns None = “scan all” (the fallback — short terms are rare and cheap).

Source

pub fn candidates(&self, terms: &[String]) -> Option<Vec<usize>>

Find candidate node indices for ALL query terms: the UNION of per-term candidates.

A node is a candidate if ANY query term’s trigrams match (because the scoring loop checks each term independently — a node that matches one term gets a non-zero score).

Trait Implementations§

Source§

impl Clone for TrigramIndex

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for TrigramIndex

Source§

fn default() -> TrigramIndex

Returns the “default value” for a type. 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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.