qdrant_client/builders/
facet_counts_builder.rs

1use crate::qdrant::*;
2
3pub struct FacetCountsBuilder {
4    /// Name of the collection
5    pub(crate) collection_name: Option<String>,
6    /// Payload key of the facet
7    pub(crate) key: Option<String>,
8    /// Filter conditions - return only those points that satisfy the specified conditions.
9    pub(crate) filter: Option<Option<Filter>>,
10    /// Max number of facets. Default is 10.
11    pub(crate) limit: Option<Option<u64>>,
12    /// If true, return exact counts, slower but useful for debugging purposes. Default is false.
13    pub(crate) exact: Option<Option<bool>>,
14    /// If set, overrides global timeout setting for this request. Unit is seconds.
15    pub(crate) timeout: Option<Option<u64>>,
16    /// Options for specifying read consistency guarantees
17    pub(crate) read_consistency: Option<Option<ReadConsistency>>,
18    /// Specify in which shards to look for the points, if not specified - look in all shards
19    pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
20}
21
22impl FacetCountsBuilder {
23    /// Name of the collection
24    #[allow(unused_mut)]
25    pub fn collection_name(self, value: String) -> Self {
26        let mut new = self;
27        new.collection_name = Option::Some(value);
28        new
29    }
30    /// Payload key of the facet
31    #[allow(unused_mut)]
32    pub fn key(self, value: String) -> Self {
33        let mut new = self;
34        new.key = Option::Some(value);
35        new
36    }
37    /// Filter conditions - return only those points that satisfy the specified conditions.
38    #[allow(unused_mut)]
39    pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
40        let mut new = self;
41        new.filter = Option::Some(Option::Some(value.into()));
42        new
43    }
44    /// Max number of facets. Default is 10.
45    #[allow(unused_mut)]
46    pub fn limit(self, value: u64) -> Self {
47        let mut new = self;
48        new.limit = Option::Some(Option::Some(value));
49        new
50    }
51    /// If true, return exact counts, slower but useful for debugging purposes. Default is false.
52    #[allow(unused_mut)]
53    pub fn exact(self, value: bool) -> Self {
54        let mut new = self;
55        new.exact = Option::Some(Option::Some(value));
56        new
57    }
58    /// If set, overrides global timeout setting for this request. Unit is seconds.
59    #[allow(unused_mut)]
60    pub fn timeout(self, value: u64) -> Self {
61        let mut new = self;
62        new.timeout = Option::Some(Option::Some(value));
63        new
64    }
65    /// Options for specifying read consistency guarantees
66    #[allow(unused_mut)]
67    pub fn read_consistency<VALUE: core::convert::Into<ReadConsistency>>(
68        self,
69        value: VALUE,
70    ) -> Self {
71        let mut new = self;
72        new.read_consistency = Option::Some(Option::Some(value.into()));
73        new
74    }
75    /// Specify in which shards to look for the points, if not specified - look in all shards
76    #[allow(unused_mut)]
77    pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
78        self,
79        value: VALUE,
80    ) -> Self {
81        let mut new = self;
82        new.shard_key_selector = Option::Some(Option::Some(value.into()));
83        new
84    }
85
86    fn build_inner(self) -> Result<FacetCounts, FacetCountsBuilderError> {
87        Ok(FacetCounts {
88            collection_name: match self.collection_name {
89                Some(value) => value,
90                None => {
91                    return Result::Err(core::convert::Into::into(
92                        ::derive_builder::UninitializedFieldError::from("collection_name"),
93                    ));
94                }
95            },
96            key: match self.key {
97                Some(value) => value,
98                None => {
99                    return Result::Err(core::convert::Into::into(
100                        ::derive_builder::UninitializedFieldError::from("key"),
101                    ));
102                }
103            },
104            filter: self.filter.unwrap_or_default(),
105            limit: self.limit.unwrap_or_default(),
106            exact: self.exact.unwrap_or_default(),
107            timeout: self.timeout.unwrap_or_default(),
108            read_consistency: self.read_consistency.unwrap_or_default(),
109            shard_key_selector: self.shard_key_selector.unwrap_or_default(),
110        })
111    }
112    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
113    fn create_empty() -> Self {
114        Self {
115            collection_name: core::default::Default::default(),
116            key: core::default::Default::default(),
117            filter: core::default::Default::default(),
118            limit: core::default::Default::default(),
119            exact: core::default::Default::default(),
120            timeout: core::default::Default::default(),
121            read_consistency: core::default::Default::default(),
122            shard_key_selector: core::default::Default::default(),
123        }
124    }
125}
126
127impl From<FacetCountsBuilder> for FacetCounts {
128    fn from(value: FacetCountsBuilder) -> Self {
129        value.build_inner().unwrap_or_else(|_| {
130            panic!(
131                "Failed to convert {0} to {1}",
132                "FacetCountsBuilder", "FacetCounts"
133            )
134        })
135    }
136}
137
138impl FacetCountsBuilder {
139    /// Builds the desired type. Can often be omitted.
140    pub fn build(self) -> FacetCounts {
141        self.build_inner().unwrap_or_else(|_| {
142            panic!(
143                "Failed to build {0} into {1}",
144                "FacetCountsBuilder", "FacetCounts"
145            )
146        })
147    }
148}
149
150impl FacetCountsBuilder {
151    pub(crate) fn empty() -> Self {
152        Self::create_empty()
153    }
154}
155
156/// Error type for FacetCountsBuilder
157#[non_exhaustive]
158#[derive(Debug)]
159pub enum FacetCountsBuilderError {
160    /// Uninitialized field
161    UninitializedField(&'static str),
162    /// Custom validation error
163    ValidationError(String),
164}
165
166// Implementing the From trait for conversion from UninitializedFieldError
167impl From<derive_builder::UninitializedFieldError> for FacetCountsBuilderError {
168    fn from(s: derive_builder::UninitializedFieldError) -> Self {
169        Self::UninitializedField(s.field_name())
170    }
171}
172
173// Implementing the From trait for conversion from String
174impl From<String> for FacetCountsBuilderError {
175    fn from(s: String) -> Self {
176        Self::ValidationError(s)
177    }
178}
179
180// Implementing the Display trait for better error messages
181impl std::fmt::Display for FacetCountsBuilderError {
182    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
183        match self {
184            Self::UninitializedField(ref field) => {
185                write!(f, "`{}` must be initialized", field)
186            }
187            Self::ValidationError(ref error) => write!(f, "{}", error),
188        }
189    }
190}
191
192// Implementing the Error trait
193impl std::error::Error for FacetCountsBuilderError {}