Skip to main content

qdrant_edge/edge/builders/
facet_request.rs

1//! Fluent builder for [`FacetRequest`].
2//!
3//! Builder fields mirror [`FacetRequest`] explicitly so adding a field
4//! to the target struct forces a compile error here.
5
6use crate::segment::json_path::JsonPath;
7use crate::segment::types::Filter;
8
9use crate::edge::requests::facet::FacetRequest;
10
11/// Fluent builder for [`FacetRequest`].
12///
13/// `key` is required and passed through [`Self::new`]; every other field is
14/// optional and falls back to the [`FacetRequest::new`] defaults.
15#[derive(Clone, Debug)]
16pub struct FacetRequestBuilder {
17    key: JsonPath,
18    limit: usize,
19    filter: Option<Filter>,
20    exact: bool,
21}
22
23impl FacetRequestBuilder {
24    pub fn new(key: JsonPath) -> Self {
25        let FacetRequest {
26            key,
27            limit,
28            filter,
29            exact,
30        } = FacetRequest::new(key);
31        Self {
32            key,
33            limit,
34            filter,
35            exact,
36        }
37    }
38
39    pub fn limit(mut self, limit: usize) -> Self {
40        self.limit = limit;
41        self
42    }
43
44    pub fn filter(mut self, filter: Filter) -> Self {
45        self.filter = Some(filter);
46        self
47    }
48
49    pub fn exact(mut self, exact: bool) -> Self {
50        self.exact = exact;
51        self
52    }
53
54    pub fn build(self) -> FacetRequest {
55        // Exhaustively destructure Self and construct FacetRequest:
56        // adding a field to either type forces a compile error here.
57        let Self {
58            key,
59            limit,
60            filter,
61            exact,
62        } = self;
63        FacetRequest {
64            key,
65            limit,
66            filter,
67            exact,
68        }
69    }
70}