Skip to main content

qdrant_client/builders/
geo_index_params_builder.rs

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