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
impl FulltextIndex
pub fn new() -> Self
Sourcepub fn is_enabled(&self, label: &str, field: &str) -> bool
pub fn is_enabled(&self, label: &str, field: &str) -> bool
Whether (label, field) is currently indexed.
Sourcepub fn field_indexed(&self, field: &str) -> bool
pub fn field_indexed(&self, field: &str) -> bool
Whether field is indexed for any label.
Sourcepub fn field_indexed_by_other(&self, label: &str, field: &str) -> bool
pub fn field_indexed_by_other(&self, label: &str, field: &str) -> bool
Whether field is indexed by a label OTHER THAN label.
Sourcepub fn enabled_pairs(&self) -> impl Iterator<Item = &(String, String)>
pub fn enabled_pairs(&self) -> impl Iterator<Item = &(String, String)>
Iterate all enabled (label, field) pairs.
Sourcepub fn enable(&mut self, label: &str, field: &str) -> bool
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).
Sourcepub fn disable(&mut self, label: &str, field: &str) -> bool
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.
Sourcepub fn add_tokens(&mut self, node_id: u32, field: &str, value: &Value)
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.
Sourcepub fn remove_node_field(&mut self, node_id: u32, field: &str)
pub fn remove_node_field(&mut self, node_id: u32, field: &str)
Remove all tokens for node_id in field’s posting list.
Sourcepub fn remove_node(&mut self, node_id: u32)
pub fn remove_node(&mut self, node_id: u32)
Remove all tokens for node_id across all indexed fields.
Sourcepub fn search(&self, field: &str, query: &str, k: usize) -> Vec<(u32, f64)>
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.
Sourcepub fn rebuild_all(
&mut self,
ids: &IdMap,
labels: &[u32],
syms: &Interner,
props: ColumnsView<'_>,
)
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
impl Clone for FulltextIndex
Source§fn clone(&self) -> FulltextIndex
fn clone(&self) -> FulltextIndex
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FulltextIndex
impl Debug for FulltextIndex
Source§impl Default for FulltextIndex
impl Default for FulltextIndex
Source§fn default() -> FulltextIndex
fn default() -> FulltextIndex
Auto Trait Implementations§
impl Freeze for FulltextIndex
impl RefUnwindSafe for FulltextIndex
impl Send for FulltextIndex
impl Sync for FulltextIndex
impl Unpin for FulltextIndex
impl UnsafeUnpin for FulltextIndex
impl UnwindSafe for FulltextIndex
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.