Skip to main content

qdrant_client/builders/
replicate_points_builder.rs

1use crate::qdrant::{Filter, ReplicatePoints, ShardKey};
2
3#[must_use]
4#[derive(Clone)]
5pub struct ReplicatePointsBuilder {
6    /// Source shard key
7    pub(crate) from_shard_key: ShardKey,
8    /// Target shard key
9    pub(crate) to_shard_key: ShardKey,
10    /// If set - only points matching the filter will be replicated
11    pub(crate) filter: Option<Option<Filter>>,
12}
13
14impl ReplicatePointsBuilder {
15    /// Create a new ReplicatePointsBuilder with required shard keys.
16    ///
17    /// # Arguments
18    ///
19    /// * `from_shard_key` - Source shard key to replicate points from
20    /// * `to_shard_key` - Target shard key to replicate points to
21    ///
22    /// # Examples
23    ///
24    /// ```
25    /// use qdrant_client::qdrant::{ReplicatePointsBuilder, ShardKey};
26    ///
27    /// let replicate = ReplicatePointsBuilder::new(
28    ///     ShardKey::from("shard_1".to_string()),
29    ///     ShardKey::from("shard_2".to_string())
30    /// ).build();
31    /// ```
32    pub fn new(from_shard_key: impl Into<ShardKey>, to_shard_key: impl Into<ShardKey>) -> Self {
33        Self {
34            from_shard_key: from_shard_key.into(),
35            to_shard_key: to_shard_key.into(),
36            filter: None,
37        }
38    }
39
40    /// Set a filter to replicate only points matching the filter.
41    ///
42    /// # Arguments
43    ///
44    /// * `filter` - Filter condition - only points matching this filter will be replicated
45    ///
46    /// # Examples
47    ///
48    /// ```
49    /// use qdrant_client::qdrant::{Condition, Filter, ReplicatePointsBuilder, ShardKey};
50    ///
51    /// let replicate = ReplicatePointsBuilder::new(
52    ///     ShardKey::from("shard_1".to_string()),
53    ///     ShardKey::from("shard_2".to_string())
54    /// )
55    /// .filter(Filter::must([Condition::matches("status", "active".to_string())]))
56    /// .build();
57    /// ```
58    pub fn filter(self, value: impl Into<Filter>) -> Self {
59        let mut new = self;
60        new.filter = Option::Some(Option::Some(value.into()));
61        new
62    }
63
64    pub fn build(self) -> ReplicatePoints {
65        ReplicatePoints {
66            from_shard_key: Some(self.from_shard_key),
67            to_shard_key: Some(self.to_shard_key),
68            filter: self.filter.unwrap_or_default(),
69        }
70    }
71}
72
73impl From<ReplicatePointsBuilder> for ReplicatePoints {
74    fn from(value: ReplicatePointsBuilder) -> Self {
75        value.build()
76    }
77}