Skip to main content

uqa_storage/sqlite/
inverted_index.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! SQLite-backed inverted index.
8
9use std::collections::{BTreeMap, BTreeSet};
10use std::sync::Arc;
11
12use rusqlite::types::Value as SqlValue;
13use rusqlite::{params, params_from_iter, OptionalExtension};
14use uqa_analysis::Analyzer;
15use uqa_core::{DocId, FieldName, IndexStats, Payload, PostingEntry, PostingList};
16
17use crate::block_max_index::{BlockMaxIndex, BlockMaxScorer, DEFAULT_BLOCK_SIZE};
18use crate::clustered_postings::{
19    ClusterPosting, ClusteredPostingCursor, EncodedScoreCluster, MaterializedPostingCursor,
20    PostingCursor,
21};
22use crate::inverted_index::{AnalyzerPhase, InvertedIndex};
23use crate::sqlite::connection::{ManagedConnection, Result as SQLiteResult, SQLiteError};
24use crate::StorageBackendResult;
25
26#[derive(Clone)]
27pub struct SQLiteInvertedIndex {
28    conn: ManagedConnection,
29    table: String,
30    analyzer: Analyzer,
31    index_field_analyzers: BTreeMap<FieldName, Analyzer>,
32    search_field_analyzers: BTreeMap<FieldName, Analyzer>,
33}
34
35#[derive(Debug)]
36struct StagedField {
37    length: u64,
38    postings: Vec<(String, Vec<u32>)>,
39}
40
41mod block_max;
42mod clustered;
43mod codec;
44mod core;
45mod maintenance;
46mod mutation;
47mod trait_impl;
48
49use clustered::{
50    clustered_result, load_cluster, load_document_terms, posting_cursor_from_rows, write_cluster,
51};
52use codec::{
53    corrupt_counter, decode_index_u64, decode_index_usize, encode_index_counter, encode_index_u64,
54    encode_index_usize, invalidate_block_max_tables, load_document_lengths, load_field_total,
55    quote_ident, table_exists, usize_to_index_u64, validate_position_count,
56};
57
58#[cfg(test)]
59mod tests;