qdrant_client/builders/
integer_index_params_builder.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use crate::qdrant::*;

pub struct IntegerIndexParamsBuilder {
    /// If true - support direct lookups.
    pub(crate) lookup: Option<Option<bool>>,
    /// If true - support ranges filters.
    pub(crate) range: Option<Option<bool>>,
    /// If true - use this key to organize storage of the collection data. This option assumes that this key will be used in majority of filtered requests.
    pub(crate) is_principal: Option<Option<bool>>,
    /// If true - store index on disk.
    pub(crate) on_disk: Option<Option<bool>>,
}

impl IntegerIndexParamsBuilder {
    pub fn new(lookup: bool, range: bool) -> Self {
        Self::create_empty().lookup(lookup).range(range)
    }

    /// If true - support direct lookups.
    #[allow(unused_mut)]
    pub fn lookup<VALUE: core::convert::Into<bool>>(self, value: VALUE) -> Self {
        let mut new = self;
        new.lookup = Option::Some(Option::Some(value.into()));
        new
    }
    /// If true - support ranges filters.
    #[allow(unused_mut)]
    pub fn range<VALUE: core::convert::Into<bool>>(self, value: VALUE) -> Self {
        let mut new = self;
        new.range = Option::Some(Option::Some(value.into()));
        new
    }
    /// If true - use this key to organize storage of the collection data. This option assumes that this key will be used in majority of filtered requests.
    #[allow(unused_mut)]
    pub fn is_principal(self, value: bool) -> Self {
        let mut new = self;
        new.is_principal = Option::Some(Option::Some(value));
        new
    }
    /// If true - store index on disk.
    #[allow(unused_mut)]
    pub fn on_disk(self, value: bool) -> Self {
        let mut new = self;
        new.on_disk = Option::Some(Option::Some(value));
        new
    }

    fn build_inner(self) -> Result<IntegerIndexParams, IntegerIndexParamsBuilderError> {
        Ok(IntegerIndexParams {
            lookup: self.lookup.unwrap_or_default(),
            range: self.range.unwrap_or_default(),
            is_principal: self.is_principal.unwrap_or_default(),
            on_disk: self.on_disk.unwrap_or_default(),
        })
    }
    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
    fn create_empty() -> Self {
        Self {
            lookup: core::default::Default::default(),
            range: core::default::Default::default(),
            is_principal: core::default::Default::default(),
            on_disk: core::default::Default::default(),
        }
    }
}

impl From<IntegerIndexParamsBuilder> for IntegerIndexParams {
    fn from(value: IntegerIndexParamsBuilder) -> Self {
        value.build_inner().unwrap_or_else(|_| {
            panic!(
                "Failed to convert {0} to {1}",
                "IntegerIndexParamsBuilder", "IntegerIndexParams"
            )
        })
    }
}

impl IntegerIndexParamsBuilder {
    /// Builds the desired type. Can often be omitted.
    pub fn build(self) -> IntegerIndexParams {
        self.build_inner().unwrap_or_else(|_| {
            panic!(
                "Failed to build {0} into {1}",
                "IntegerIndexParamsBuilder", "IntegerIndexParams"
            )
        })
    }
}

impl Default for IntegerIndexParamsBuilder {
    fn default() -> Self {
        Self::create_empty()
    }
}

/// Error type for IntegerIndexParamsBuilder
#[non_exhaustive]
#[derive(Debug)]
pub enum IntegerIndexParamsBuilderError {
    /// Uninitialized field
    UninitializedField(&'static str),
    /// Custom validation error
    ValidationError(String),
}

// Implementing the Display trait for better error messages
impl std::fmt::Display for IntegerIndexParamsBuilderError {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            Self::UninitializedField(field) => {
                write!(f, "`{}` must be initialized", field)
            }
            Self::ValidationError(error) => write!(f, "{}", error),
        }
    }
}

// Implementing the Error trait
impl std::error::Error for IntegerIndexParamsBuilderError {}

// Implementing From trait for conversion from UninitializedFieldError
impl From<derive_builder::UninitializedFieldError> for IntegerIndexParamsBuilderError {
    fn from(error: derive_builder::UninitializedFieldError) -> Self {
        Self::UninitializedField(error.field_name())
    }
}

// Implementing From trait for conversion from String
impl From<String> for IntegerIndexParamsBuilderError {
    fn from(error: String) -> Self {
        Self::ValidationError(error)
    }
}