sift_core/index/trigram/
mod.rs1pub mod builder;
2pub mod file_table;
3pub mod key;
4mod lifecycle;
5mod search;
6pub mod storage;
7
8use std::path::{Path, PathBuf};
9
10use crate::index::{CorpusKind, FileId};
11
12use self::file_table::FileFingerprint;
13pub use key::Trigram;
14
15#[derive(Debug, thiserror::Error)]
17pub enum TrigramIndexError {
18 #[error("index component missing: {0}")]
19 MissingComponent(PathBuf),
20
21 #[error("IO error: {0}")]
22 Io(#[from] std::io::Error),
23}
24
25#[derive(Debug)]
36pub struct TrigramIndex {
37 root: PathBuf,
38 pub(crate) fingerprints: Vec<FileFingerprint>,
39 trigram_sets: storage::trigram_sets::TrigramSets,
40 lexicon: storage::lexicon::Lexicon,
41 postings: storage::postings::Postings,
42 corpus_kind: CorpusKind,
43}
44
45impl TrigramIndex {
46 #[must_use]
47 pub fn file_path(&self, id: FileId) -> Option<&Path> {
48 self.fingerprints.get(id.get()).map(|fp| fp.path.as_path())
49 }
50
51 #[must_use]
52 pub fn file_abs_path(&self, id: FileId) -> Option<PathBuf> {
53 self.fingerprints
54 .get(id.get())
55 .map(|fp| self.root.join(&fp.path))
56 }
57
58 #[must_use]
59 pub fn root(&self) -> &Path {
60 &self.root
61 }
62
63 #[must_use]
64 pub const fn corpus_kind(&self) -> CorpusKind {
65 self.corpus_kind
66 }
67}