uqa_storage/sqlite/inverted_index/
core.rs1use super::{
10 Analyzer, BTreeMap, InvertedIndex, ManagedConnection, SQLiteInvertedIndex,
11 StorageBackendResult, 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 analyzer,
22 index_field_analyzers: BTreeMap::new(),
23 search_field_analyzers: BTreeMap::new(),
24 }
25 }
26
27 pub fn tokenize(&self, text: &str, field: &str) -> StorageBackendResult<Vec<String>> {
29 let analyzer = self
30 .index_field_analyzers
31 .get(field)
32 .unwrap_or(&self.analyzer);
33 Ok(analyzer.analyze(text)?)
34 }
35
36 pub fn skip_table_name(&self, field: &str) -> String {
37 format!("_skip_{}_{}", self.table, field)
38 }
39
40 pub fn blockmax_table_name(&self, field: &str) -> String {
41 format!("_blockmax_{}_{}", self.table, field)
42 }
43
44 pub fn flush_skip_pointers(&self) -> StorageBackendResult<()> {
45 let fields = self.field_names()?;
46 for field in fields {
47 self.rebuild_skip_pointers_for_field(&field)?;
48 }
49 Ok(())
50 }
51}