qdrant_client/builders/
facet_counts_builder.rs

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