qdrant_client/builders/
integer_index_params_builder.rs

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