Skip to main content

Index

Struct Index 

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

A lazily-maintained fst-segment index rooted at a directory (.ct/okf/).

Implementations§

Source§

impl Index

Source

pub fn open(dir: &Path) -> Result<Index, String>

Open the index at dir, loading manifest.json if present (an absent or unreadable manifest yields an empty index). The directory is created on the first Index::save.

Source

pub fn doc_count(&self) -> usize

Number of live (non-tombstoned) documents.

Source

pub fn segment_count(&self) -> usize

Number of live segments.

Source

pub fn tombstone_count(&self) -> usize

Number of tombstoned documents awaiting condense.

Source

pub fn pending(&self, current: &[FileStat]) -> (usize, usize, usize)

How many of current are new / changed / removed relative to the manifest — a read-only staleness probe for index status that mutates nothing (the same diff update would act on).

Source

pub fn update<F>( &mut self, current: &[FileStat], load: F, ) -> Result<UpdateReport, String>
where F: Fn(&FileStat) -> Result<DocSource, String>,

Reconcile the index against current (the live files of the OKF roots), re-indexing only what changed. load is called to read a file’s DocSource only when it is new or modified. Writes at most one new segment. Call save afterwards to persist the manifest.

Source

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

Search the index, returning up to limit hits ranked by a tf-idf score. Reads every live segment; tombstoned documents are filtered out.

Source

pub fn condense(&mut self) -> Result<bool, String>

Merge every segment into one, dropping tombstoned documents and their postings, then delete the old segment files. Reclaims space without re-reading any source file. A no-op when there is nothing to gain (≤1 segment and no tombstones).

Source

pub fn reset(&mut self)

Discard the whole index (segments + manifest state), so the next update re-indexes every file from scratch.

Source

pub fn save(&self) -> Result<(), String>

Persist manifest.json (creating the index directory if needed).

Auto Trait Implementations§

§

impl Freeze for Index

§

impl RefUnwindSafe for Index

§

impl Send for Index

§

impl Sync for Index

§

impl Unpin for Index

§

impl UnsafeUnpin for Index

§

impl UnwindSafe for Index

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> 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> 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, 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.