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