cipherstash_config/column/index/
mod.rs1mod array_index_mode;
2mod index_type;
3mod ste_vec_mode;
4
5use crate::{operator::Operator, ColumnType};
6pub use array_index_mode::ArrayIndexMode;
7pub use index_type::IndexType;
8use serde::{Deserialize, Serialize};
9pub use ste_vec_mode::SteVecMode;
10
11pub const K_DEFAULT: usize = 6;
12pub const M_DEFAULT: usize = 2048;
13
14#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)]
15#[serde(tag = "kind", rename_all = "kebab-case")]
16pub enum Tokenizer {
17 EdgeNgram { min_gram: usize, max_gram: usize },
18 Ngram { token_length: usize },
19 Standard,
20}
21
22#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)]
23#[serde(tag = "kind", rename_all = "kebab-case")]
24pub enum TokenFilter {
25 Upcase,
26 Downcase,
27 Stemmer,
28 Stop,
29}
30
31#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
32pub struct Index {
33 pub version: usize,
34
35 #[serde(flatten)]
36 pub index_type: IndexType,
37}
38
39impl Index {
40 pub fn new(index_type: IndexType) -> Self {
41 Self {
42 version: 1,
43 index_type,
44 }
45 }
46
47 pub fn new_match() -> Self {
48 Self::new(IndexType::Match {
49 token_filters: vec![TokenFilter::Downcase],
50 tokenizer: Tokenizer::Ngram { token_length: 3 },
51 m: M_DEFAULT,
52 k: K_DEFAULT,
53 include_original: true,
54 })
55 }
56
57 pub fn new_ore() -> Self {
58 Self::new(IndexType::Ore)
59 }
60
61 pub fn new_ope() -> Self {
62 Self::new(IndexType::Ope)
63 }
64
65 pub fn new_unique() -> Self {
66 Self::new(IndexType::Unique {
67 token_filters: vec![],
68 })
69 }
70
71 pub fn supports(&self, op: &Operator, cast_type: &ColumnType) -> bool {
72 self.index_type.supports(op, cast_type)
73 }
74
75 pub fn is_orderable(&self) -> bool {
76 self.index_type.is_orderable()
77 }
78
79 pub fn as_str(&self) -> &str {
82 self.index_type.as_str()
83 }
84
85 pub fn is_match(&self) -> bool {
86 matches!(&self.index_type, IndexType::Match { .. })
87 }
88
89 pub fn is_ore(&self) -> bool {
90 matches!(&self.index_type, IndexType::Ore)
91 }
92
93 pub fn is_ope(&self) -> bool {
94 matches!(&self.index_type, IndexType::Ope)
95 }
96
97 pub fn is_unique(&self) -> bool {
98 matches!(&self.index_type, IndexType::Unique { .. })
99 }
100
101 pub fn is_ste_vec(&self) -> bool {
102 matches!(&self.index_type, IndexType::SteVec { .. })
103 }
104}