qdrant_client/builders/
integer_index_params_builder.rs

1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct IntegerIndexParamsBuilder {
5    /// If true - support direct lookups.
6    pub(crate) lookup: Option<Option<bool>>,
7    /// If true - support ranges filters.
8    pub(crate) range: Option<Option<bool>>,
9    /// 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.
10    pub(crate) is_principal: Option<Option<bool>>,
11    /// If true - store index on disk.
12    pub(crate) on_disk: Option<Option<bool>>,
13}
14
15impl IntegerIndexParamsBuilder {
16    pub fn new(lookup: bool, range: bool) -> Self {
17        Self::create_empty().lookup(lookup).range(range)
18    }
19
20    /// If true - support direct lookups.
21    pub fn lookup<VALUE: core::convert::Into<bool>>(self, value: VALUE) -> Self {
22        let mut new = self;
23        new.lookup = Option::Some(Option::Some(value.into()));
24        new
25    }
26    /// If true - support ranges filters.
27    pub fn range<VALUE: core::convert::Into<bool>>(self, value: VALUE) -> Self {
28        let mut new = self;
29        new.range = Option::Some(Option::Some(value.into()));
30        new
31    }
32    /// 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.
33    pub fn is_principal(self, value: bool) -> Self {
34        let mut new = self;
35        new.is_principal = Option::Some(Option::Some(value));
36        new
37    }
38    /// If true - store index on disk.
39    pub fn on_disk(self, value: bool) -> Self {
40        let mut new = self;
41        new.on_disk = Option::Some(Option::Some(value));
42        new
43    }
44
45    fn build_inner(self) -> Result<IntegerIndexParams, IntegerIndexParamsBuilderError> {
46        Ok(IntegerIndexParams {
47            lookup: self.lookup.unwrap_or_default(),
48            range: self.range.unwrap_or_default(),
49            is_principal: self.is_principal.unwrap_or_default(),
50            on_disk: self.on_disk.unwrap_or_default(),
51        })
52    }
53    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
54    fn create_empty() -> Self {
55        Self {
56            lookup: core::default::Default::default(),
57            range: core::default::Default::default(),
58            is_principal: core::default::Default::default(),
59            on_disk: core::default::Default::default(),
60        }
61    }
62}
63
64impl From<IntegerIndexParamsBuilder> for IntegerIndexParams {
65    fn from(value: IntegerIndexParamsBuilder) -> Self {
66        value.build_inner().unwrap_or_else(|_| {
67            panic!(
68                "Failed to convert {0} to {1}",
69                "IntegerIndexParamsBuilder", "IntegerIndexParams"
70            )
71        })
72    }
73}
74
75impl IntegerIndexParamsBuilder {
76    /// Builds the desired type. Can often be omitted.
77    pub fn build(self) -> IntegerIndexParams {
78        self.build_inner().unwrap_or_else(|_| {
79            panic!(
80                "Failed to build {0} into {1}",
81                "IntegerIndexParamsBuilder", "IntegerIndexParams"
82            )
83        })
84    }
85}
86
87impl Default for IntegerIndexParamsBuilder {
88    fn default() -> Self {
89        Self::create_empty()
90    }
91}
92
93/// Error type for IntegerIndexParamsBuilder
94#[non_exhaustive]
95#[derive(Debug)]
96pub enum IntegerIndexParamsBuilderError {
97    /// Uninitialized field
98    UninitializedField(&'static str),
99    /// Custom validation error
100    ValidationError(String),
101}
102
103// Implementing the Display trait for better error messages
104impl std::fmt::Display for IntegerIndexParamsBuilderError {
105    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
106        match self {
107            Self::UninitializedField(field) => {
108                write!(f, "`{field}` must be initialized")
109            }
110            Self::ValidationError(error) => write!(f, "{error}"),
111        }
112    }
113}
114
115// Implementing the Error trait
116impl std::error::Error for IntegerIndexParamsBuilderError {}
117
118// Implementing From trait for conversion from UninitializedFieldError
119impl From<derive_builder::UninitializedFieldError> for IntegerIndexParamsBuilderError {
120    fn from(error: derive_builder::UninitializedFieldError) -> Self {
121        Self::UninitializedField(error.field_name())
122    }
123}
124
125// Implementing From trait for conversion from String
126impl From<String> for IntegerIndexParamsBuilderError {
127    fn from(error: String) -> Self {
128        Self::ValidationError(error)
129    }
130}