Skip to main content

qdrant_client/builders/
bool_index_params_builder.rs

1use crate::qdrant::*;
2
3#[must_use]
4#[derive(Clone)]
5pub struct BoolIndexParamsBuilder {
6    /// If true - store index on disk.
7    pub(crate) on_disk: Option<Option<bool>>,
8    /// If true - enable HNSW index for this field.
9    pub(crate) enable_hnsw: Option<Option<bool>>,
10    /// Memory placement of the index.
11    pub(crate) memory: Option<Option<i32>>,
12    /// Index every object of this array as a separate entry.
13    pub(crate) nested: Option<Option<String>>,
14}
15
16impl Default for BoolIndexParamsBuilder {
17    fn default() -> Self {
18        Self::new()
19    }
20}
21
22impl BoolIndexParamsBuilder {
23    pub fn new() -> Self {
24        Self::create_empty()
25    }
26
27    /// If true - store index on disk.
28    ///
29    /// Deprecated since 1.19.0, use [`memory`](Self::memory) instead.
30    pub fn on_disk(self, value: bool) -> Self {
31        let mut new = self;
32        new.on_disk = Option::Some(Option::Some(value));
33        new
34    }
35    /// If true - enable HNSW index for this field.
36    pub fn enable_hnsw(self, value: bool) -> Self {
37        let mut new = self;
38        new.enable_hnsw = Option::Some(Option::Some(value));
39        new
40    }
41    /// Memory placement of the index.
42    /// Overrides the deprecated `on_disk` flag if both are set.
43    pub fn memory<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
44        let mut new = self;
45        new.memory = Option::Some(Option::Some(value.into()));
46        new
47    }
48    /// Index every object of this array as a separate entry, e.g. `offers` for the field `offers[].price`.
49    /// The field must be inside the array's elements.
50    pub fn nested(self, value: impl Into<String>) -> Self {
51        let mut new = self;
52        new.nested = Option::Some(Option::Some(value.into()));
53        new
54    }
55
56    #[allow(deprecated)]
57    fn build_inner(self) -> Result<BoolIndexParams, std::convert::Infallible> {
58        Ok(BoolIndexParams {
59            on_disk: self.on_disk.unwrap_or_default(),
60            enable_hnsw: self.enable_hnsw.unwrap_or_default(),
61            memory: self.memory.unwrap_or_default(),
62            nested: self.nested.unwrap_or_default(),
63        })
64    }
65    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
66    fn create_empty() -> Self {
67        Self {
68            on_disk: core::default::Default::default(),
69            enable_hnsw: core::default::Default::default(),
70            memory: core::default::Default::default(),
71            nested: core::default::Default::default(),
72        }
73    }
74}
75
76impl From<BoolIndexParamsBuilder> for BoolIndexParams {
77    fn from(value: BoolIndexParamsBuilder) -> Self {
78        value.build_inner().unwrap_or_else(|_| {
79            panic!(
80                "Failed to convert {0} to {1}",
81                "BoolIndexParamsBuilder", "BoolIndexParams"
82            )
83        })
84    }
85}
86
87impl BoolIndexParamsBuilder {
88    /// Builds the desired type. Can often be omitted.
89    pub fn build(self) -> BoolIndexParams {
90        self.build_inner().unwrap_or_else(|_| {
91            panic!(
92                "Failed to build {0} into {1}",
93                "BoolIndexParamsBuilder", "BoolIndexParams"
94            )
95        })
96    }
97}