Skip to main content

uqa_storage_sqlite/inverted_index/
core.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Construction, analyzer selection, and physical auxiliary names.
8
9use super::{
10    Analyzer, InvertedIndex, ManagedConnection, SQLiteInvertedIndex, StorageBackendResult,
11    DEFAULT_BLOCK_SIZE,
12};
13
14impl SQLiteInvertedIndex {
15    pub const BLOCK_SIZE: usize = DEFAULT_BLOCK_SIZE;
16
17    pub fn new(conn: ManagedConnection, table: impl Into<String>, analyzer: Analyzer) -> Self {
18        Self {
19            conn,
20            table: table.into(),
21            bindings: uqa_storage::inverted_index::AnalyzerBindings::new(analyzer),
22            retention_control: uqa_storage::read_control::StorageReadControl::with_limit(
23                uqa_storage::mvcc::VersionedSessionOptions::default().retained_bytes,
24            ),
25        }
26    }
27
28    /// Tokenize `text` with the analyzer bound to `field`.
29    pub fn tokenize(&self, text: &str, field: &str) -> StorageBackendResult<Vec<String>> {
30        Ok(self.bindings.index_revision(field)?.analyze(text)?)
31    }
32
33    pub fn skip_table_name(&self, field: &str) -> String {
34        format!("_skip_{}_{}", self.table, field)
35    }
36
37    pub fn blockmax_table_name(&self, field: &str) -> String {
38        format!("_blockmax_{}_{}", self.table, field)
39    }
40
41    pub fn flush_skip_pointers(&self) -> StorageBackendResult<()> {
42        if let Some(index) = self.native_index() {
43            return index.flush_skip_pointers();
44        }
45        let fields = self.field_names()?;
46        for field in fields {
47            self.rebuild_skip_pointers_for_field(&field)?;
48        }
49        Ok(())
50    }
51}