Skip to main content

PostingList

Struct PostingList 

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

In-memory inverted index. See module-level doc.

Implementations§

Source§

impl PostingList

Source

pub fn new() -> Self

Empty index with no postings and no documents.

Source

pub fn len(&self) -> usize

Number of indexed documents.

Source

pub fn is_empty(&self) -> bool

True iff no document has been inserted (or all have been removed).

Source

pub fn avg_doc_len(&self) -> f64

Average document length in tokens. Returns 0.0 when the index is empty so BM25 can guard cleanly without a div-by-zero.

Source

pub fn serialize_doc_lengths(&self) -> Vec<(i64, u32)>

Phase 8c — emit (rowid, doc_len) pairs for every indexed doc, in ascending rowid order. The pager writes these into the FTS index’s doc-lengths sidecar cell; reload feeds them back to Self::from_persisted_postings.

Source

pub fn serialize_postings(&self) -> Vec<(String, Vec<(i64, u32)>)>

Phase 8c — emit (term, [(rowid, term_freq)]) triples in lexicographic term order; per-term entries are in ascending rowid order (the underlying BTreeMap already guarantees this). One element per unique indexed term; pager writes one cell per element.

Source

pub fn from_persisted_postings<I, J>(doc_lengths: I, postings: J) -> Self
where I: IntoIterator<Item = (i64, u32)>, J: IntoIterator<Item = (String, Vec<(i64, u32)>)>,

Phase 8c — rebuild a PostingList directly from the persisted doc-lengths sidecar + per-term postings. No tokenization runs; the resulting index is byte-equivalent to what was saved (assuming the input came from serialize_*).

doc_lengths is the full (rowid, doc_len) map written into the sidecar cell. postings is one (term, [(rowid, tf)]) element per term cell.

Source

pub fn insert(&mut self, rowid: i64, text: &str)

Tokenize text and add its postings under rowid. If rowid is already indexed, its previous postings are removed first — i.e. insert is idempotent for re-indexing the same row.

A row whose tokenization yields zero tokens is still recorded (with doc_len = 0 and no posting entries). This keeps len() honest for “indexed but empty” rows; BM25 returns 0.0 for them.

Source

pub fn remove(&mut self, rowid: i64)

Remove all postings for rowid. No-op if rowid was never inserted. Empty per-term posting lists left behind by the last referencing row are pruned to keep the BTreeMap tight.

Source

pub fn matches(&self, rowid: i64, query: &str) -> bool

True iff rowid is indexed and at least one of its terms is in the (tokenized) query. Powers fts_match(col, 'q') in 8b without going through scoring.

Source

pub fn score(&self, rowid: i64, query: &str, params: &Bm25Params) -> f64

BM25 score for a single (rowid, query) pair. Returns 0.0 if rowid is unknown or no query terms hit.

Source

pub fn query(&self, query: &str, params: &Bm25Params) -> Vec<(i64, f64)>

Score every doc that contains at least one query term and return (rowid, score) sorted by score descending, ties broken by rowid ascending. Powers the bulk path used by 8b’s try_fts_probe optimizer hook.

Empty query → empty result. Empty index → empty result. Rows that don’t match any query term are not scored at all (they would score 0.0 — including them just bloats the result).

Trait Implementations§

Source§

impl Clone for PostingList

Source§

fn clone(&self) -> PostingList

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 PostingList

Source§

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

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

impl Default for PostingList

Source§

fn default() -> PostingList

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.