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::connection::{ManagedConnection, Result as SQLiteResult, SQLiteError};
18use uqa_storage::block_max_index::{BlockMaxIndex, BlockMaxScorer, DEFAULT_BLOCK_SIZE};
19use uqa_storage::clustered_postings::{
20    ClusteredPostingCursor, EncodedScoreCluster, MaterializedPostingCursor, OccurrencePosting,
21    PostingCursor,
22};
23use uqa_storage::inverted_index::{
24    AnalyzerPhase, IndexedFieldMetadata, IndexedFieldRevision, InvertedIndex,
25};
26use uqa_storage::StorageBackendResult;
27use uqa_storage::TokenTermKey;
28
29#[derive(Clone)]
30pub struct SQLiteInvertedIndex {
31    conn: ManagedConnection,
32    table: String,
33    bindings: uqa_storage::inverted_index::AnalyzerBindings,
34    retention_control: uqa_storage::read_control::StorageReadControl,
35}
36
37#[derive(Debug)]
38struct StagedField {
39    metadata: IndexedFieldMetadata,
40    postings: BTreeMap<TokenTermKey, Vec<uqa_core::TokenOccurrence>>,
41}
42
43mod block_max;
44mod clustered;
45mod codec;
46mod controlled;
47mod core;
48mod data;
49mod format;
50mod maintenance;
51mod mutation;
52mod native;
53pub(crate) use native::NativeOccurrenceRecords;
54mod queries;
55mod records;
56mod snapshot;
57mod trait_impl;
58
59use clustered::{clustered_result, load_cluster, posting_cursor_from_rows, write_cluster};
60use codec::{
61    decode_index_u64, decode_index_usize, encode_index_counter, encode_index_u64,
62    encode_index_usize, invalidate_posting_accelerators, load_document_lengths, quote_ident,
63    table_exists,
64};
65
66#[cfg(test)]
67mod tests;