Skip to main content

FulltextIndex

Struct FulltextIndex 

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

Incremental inverted index for full-text BM25 search.

Enabled per (label, field) pair via FulltextIndex::enable. Postings store stemmed tokens with per-document position lists for phrase adjacency checking. Doc lengths are tracked separately for BM25 normalization.

§BM25 constants

k1 = 1.2, b = 0.75 (Okapi BM25 defaults).

§WAL / persistence

The index is NOT stored in the V8 snapshot. It is rebuilt from WAL replay (EnableFulltext / DisableFulltext records + node property re-indexing) at open time via FulltextIndex::rebuild_all. Postings restructuring in v2 has no snapshot format impact.

Implementations§

Source§

impl FulltextIndex

Source

pub fn new() -> Self

Source

pub fn is_enabled(&self, label: &str, field: &str) -> bool

Whether (label, field) is currently indexed.

Source

pub fn has_label(&self, label: &str) -> bool

Whether any field is enabled for this label.

Source

pub fn field_indexed(&self, field: &str) -> bool

Whether field is indexed for any label.

Source

pub fn field_indexed_by_other(&self, label: &str, field: &str) -> bool

Whether field is indexed by a label OTHER THAN label.

Source

pub fn enabled_pairs(&self) -> impl Iterator<Item = &(String, String)>

Iterate all enabled (label, field) pairs.

Source

pub fn enable(&mut self, label: &str, field: &str) -> bool

Enable full-text indexing for (label, field). Returns true if newly added, false if already present (idempotent for replay safety).

Source

pub fn disable(&mut self, label: &str, field: &str) -> bool

Disable full-text indexing for (label, field). Drops all postings and doc_len entries for that field. Returns true if the pair was present and removed.

Source

pub fn add_tokens(&mut self, node_id: u32, field: &str, value: &Value)

Add stemmed tokens (with positions) for value under (node_id, field). Replaces any existing doc_len entry for this node. Caller is responsible for ensuring (label, field) is enabled.

Source

pub fn remove_node_field(&mut self, node_id: u32, field: &str)

Remove all tokens for node_id in field’s posting list.

Source

pub fn remove_node(&mut self, node_id: u32)

Remove all tokens for node_id across all indexed fields.

Source

pub fn search(&self, field: &str, query: &str, k: usize) -> Vec<(u32, f64)>

Search a field with a v2 query. Returns (node_id, bm25_score) sorted by score descending, ties by node_id ascending. Returns empty if the field is not indexed or the query produces no groups.

BM25 constants: k1 = 1.2, b = 0.75. Scores are summed across matched OR-groups; negated atoms exclude a document; phrase atoms require positional adjacency. If k > 0, only the top-k results are returned.

Source

pub fn rebuild_all( &mut self, ids: &IdMap, labels: &[u32], syms: &Interner, props: ColumnsView<'_>, )

Rebuild the entire index from scratch.

Called once after WAL replay to correct any drift accumulated by incremental add_tokens / remove_node_field calls during per-record apply.

Trait Implementations§

Source§

impl Clone for FulltextIndex

Source§

fn clone(&self) -> FulltextIndex

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 Debug for FulltextIndex

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for FulltextIndex

Source§

fn default() -> FulltextIndex

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

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
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 = !

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.