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