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