Skip to main content

couchbase_core/searchx/
mgmt_options.rs

1/*
2 *
3 *  * Copyright (c) 2025 Couchbase, Inc.
4 *  *
5 *  * Licensed under the Apache License, Version 2.0 (the "License");
6 *  * you may not use this file except in compliance with the License.
7 *  * You may obtain a copy of the License at
8 *  *
9 *  *    http://www.apache.org/licenses/LICENSE-2.0
10 *  *
11 *  * Unless required by applicable law or agreed to in writing, software
12 *  * distributed under the License is distributed on an "AS IS" BASIS,
13 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  * See the License for the specific language governing permissions and
15 *  * limitations under the License.
16 *
17 */
18
19use crate::httpx::client::Client;
20use crate::httpx::request::OnBehalfOfInfo;
21use crate::mgmtx::node_target::NodeTarget;
22use crate::searchx::ensure_index_helper::DesiredState;
23use crate::searchx::index::Index;
24use std::sync::Arc;
25
26#[derive(Debug)]
27#[non_exhaustive]
28pub struct UpsertIndexOptions<'a> {
29    pub index: &'a Index,
30    pub bucket_name: Option<&'a str>,
31    pub scope_name: Option<&'a str>,
32    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
33}
34
35impl<'a> UpsertIndexOptions<'a> {
36    pub fn new(index: &'a Index) -> Self {
37        Self {
38            index,
39            bucket_name: None,
40            scope_name: None,
41            on_behalf_of: None,
42        }
43    }
44
45    pub fn bucket_name(mut self, bucket_name: impl Into<Option<&'a str>>) -> Self {
46        self.bucket_name = bucket_name.into();
47        self
48    }
49
50    pub fn scope_name(mut self, scope_name: impl Into<Option<&'a str>>) -> Self {
51        self.scope_name = scope_name.into();
52        self
53    }
54
55    pub fn on_behalf_of(mut self, on_behalf_of: impl Into<Option<&'a OnBehalfOfInfo>>) -> Self {
56        self.on_behalf_of = on_behalf_of.into();
57        self
58    }
59}
60
61#[derive(Debug)]
62#[non_exhaustive]
63pub struct DeleteIndexOptions<'a> {
64    pub index_name: &'a str,
65    pub bucket_name: Option<&'a str>,
66    pub scope_name: Option<&'a str>,
67    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
68}
69
70impl<'a> DeleteIndexOptions<'a> {
71    pub fn new(index_name: &'a str) -> Self {
72        Self {
73            index_name,
74            bucket_name: None,
75            scope_name: None,
76            on_behalf_of: None,
77        }
78    }
79
80    pub fn bucket_name(mut self, bucket_name: impl Into<Option<&'a str>>) -> Self {
81        self.bucket_name = bucket_name.into();
82        self
83    }
84
85    pub fn scope_name(mut self, scope_name: impl Into<Option<&'a str>>) -> Self {
86        self.scope_name = scope_name.into();
87        self
88    }
89
90    pub fn on_behalf_of(mut self, on_behalf_of: impl Into<Option<&'a OnBehalfOfInfo>>) -> Self {
91        self.on_behalf_of = on_behalf_of.into();
92        self
93    }
94}
95
96#[derive(Debug)]
97#[non_exhaustive]
98pub struct GetIndexOptions<'a> {
99    pub index_name: &'a str,
100    pub bucket_name: Option<&'a str>,
101    pub scope_name: Option<&'a str>,
102    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
103}
104
105impl<'a> GetIndexOptions<'a> {
106    pub fn new(index_name: &'a str) -> Self {
107        Self {
108            index_name,
109            bucket_name: None,
110            scope_name: None,
111            on_behalf_of: None,
112        }
113    }
114
115    pub fn bucket_name(mut self, bucket_name: impl Into<Option<&'a str>>) -> Self {
116        self.bucket_name = bucket_name.into();
117        self
118    }
119
120    pub fn scope_name(mut self, scope_name: impl Into<Option<&'a str>>) -> Self {
121        self.scope_name = scope_name.into();
122        self
123    }
124
125    pub fn on_behalf_of(mut self, on_behalf_of: impl Into<Option<&'a OnBehalfOfInfo>>) -> Self {
126        self.on_behalf_of = on_behalf_of.into();
127        self
128    }
129}
130
131#[derive(Default, Debug)]
132#[non_exhaustive]
133pub struct GetAllIndexesOptions<'a> {
134    pub bucket_name: Option<&'a str>,
135    pub scope_name: Option<&'a str>,
136    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
137}
138
139impl<'a> GetAllIndexesOptions<'a> {
140    pub fn new() -> Self {
141        Self {
142            bucket_name: None,
143            scope_name: None,
144            on_behalf_of: None,
145        }
146    }
147
148    pub fn bucket_name(mut self, bucket_name: impl Into<Option<&'a str>>) -> Self {
149        self.bucket_name = bucket_name.into();
150        self
151    }
152
153    pub fn scope_name(mut self, scope_name: impl Into<Option<&'a str>>) -> Self {
154        self.scope_name = scope_name.into();
155        self
156    }
157
158    pub fn on_behalf_of(mut self, on_behalf_of: impl Into<Option<&'a OnBehalfOfInfo>>) -> Self {
159        self.on_behalf_of = on_behalf_of.into();
160        self
161    }
162}
163
164#[derive(Debug)]
165#[non_exhaustive]
166pub struct AnalyzeDocumentOptions<'a> {
167    pub index_name: &'a str,
168    pub doc_content: &'a [u8],
169    pub bucket_name: Option<&'a str>,
170    pub scope_name: Option<&'a str>,
171    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
172}
173
174impl<'a> AnalyzeDocumentOptions<'a> {
175    pub fn new(index_name: &'a str, doc_content: &'a [u8]) -> Self {
176        Self {
177            index_name,
178            doc_content,
179            bucket_name: None,
180            scope_name: None,
181            on_behalf_of: None,
182        }
183    }
184
185    pub fn bucket_name(mut self, bucket_name: impl Into<Option<&'a str>>) -> Self {
186        self.bucket_name = bucket_name.into();
187        self
188    }
189
190    pub fn scope_name(mut self, scope_name: impl Into<Option<&'a str>>) -> Self {
191        self.scope_name = scope_name.into();
192        self
193    }
194
195    pub fn on_behalf_of(mut self, on_behalf_of: impl Into<Option<&'a OnBehalfOfInfo>>) -> Self {
196        self.on_behalf_of = on_behalf_of.into();
197        self
198    }
199}
200
201#[derive(Debug)]
202#[non_exhaustive]
203pub struct GetIndexedDocumentsCountOptions<'a> {
204    pub bucket_name: Option<&'a str>,
205    pub scope_name: Option<&'a str>,
206    pub index_name: &'a str,
207    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
208}
209
210impl<'a> GetIndexedDocumentsCountOptions<'a> {
211    pub fn new(index_name: &'a str) -> Self {
212        Self {
213            bucket_name: None,
214            scope_name: None,
215            index_name,
216            on_behalf_of: None,
217        }
218    }
219
220    pub fn bucket_name(mut self, bucket_name: impl Into<Option<&'a str>>) -> Self {
221        self.bucket_name = bucket_name.into();
222        self
223    }
224
225    pub fn scope_name(mut self, scope_name: impl Into<Option<&'a str>>) -> Self {
226        self.scope_name = scope_name.into();
227        self
228    }
229
230    pub fn on_behalf_of(mut self, on_behalf_of: impl Into<Option<&'a OnBehalfOfInfo>>) -> Self {
231        self.on_behalf_of = on_behalf_of.into();
232        self
233    }
234}
235
236#[derive(Debug)]
237#[non_exhaustive]
238pub struct PauseIngestOptions<'a> {
239    pub bucket_name: Option<&'a str>,
240    pub scope_name: Option<&'a str>,
241    pub index_name: &'a str,
242    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
243}
244
245impl<'a> PauseIngestOptions<'a> {
246    pub fn new(index_name: &'a str) -> Self {
247        Self {
248            bucket_name: None,
249            scope_name: None,
250            index_name,
251            on_behalf_of: None,
252        }
253    }
254
255    pub fn bucket_name(mut self, bucket_name: impl Into<Option<&'a str>>) -> Self {
256        self.bucket_name = bucket_name.into();
257        self
258    }
259
260    pub fn scope_name(mut self, scope_name: impl Into<Option<&'a str>>) -> Self {
261        self.scope_name = scope_name.into();
262        self
263    }
264
265    pub fn on_behalf_of(mut self, on_behalf_of: impl Into<Option<&'a OnBehalfOfInfo>>) -> Self {
266        self.on_behalf_of = on_behalf_of.into();
267        self
268    }
269}
270
271#[derive(Debug)]
272#[non_exhaustive]
273pub struct ResumeIngestOptions<'a> {
274    pub bucket_name: Option<&'a str>,
275    pub scope_name: Option<&'a str>,
276    pub index_name: &'a str,
277    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
278}
279
280impl<'a> ResumeIngestOptions<'a> {
281    pub fn new(index_name: &'a str) -> Self {
282        Self {
283            bucket_name: None,
284            scope_name: None,
285            index_name,
286            on_behalf_of: None,
287        }
288    }
289
290    pub fn bucket_name(mut self, bucket_name: impl Into<Option<&'a str>>) -> Self {
291        self.bucket_name = bucket_name.into();
292        self
293    }
294
295    pub fn scope_name(mut self, scope_name: impl Into<Option<&'a str>>) -> Self {
296        self.scope_name = scope_name.into();
297        self
298    }
299
300    pub fn on_behalf_of(mut self, on_behalf_of: impl Into<Option<&'a OnBehalfOfInfo>>) -> Self {
301        self.on_behalf_of = on_behalf_of.into();
302        self
303    }
304}
305
306#[derive(Debug)]
307#[non_exhaustive]
308pub struct AllowQueryingOptions<'a> {
309    pub bucket_name: Option<&'a str>,
310    pub scope_name: Option<&'a str>,
311    pub index_name: &'a str,
312    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
313}
314
315impl<'a> AllowQueryingOptions<'a> {
316    pub fn new(index_name: &'a str) -> Self {
317        Self {
318            bucket_name: None,
319            scope_name: None,
320            index_name,
321            on_behalf_of: None,
322        }
323    }
324
325    pub fn bucket_name(mut self, bucket_name: impl Into<Option<&'a str>>) -> Self {
326        self.bucket_name = bucket_name.into();
327        self
328    }
329
330    pub fn scope_name(mut self, scope_name: impl Into<Option<&'a str>>) -> Self {
331        self.scope_name = scope_name.into();
332        self
333    }
334
335    pub fn on_behalf_of(mut self, on_behalf_of: impl Into<Option<&'a OnBehalfOfInfo>>) -> Self {
336        self.on_behalf_of = on_behalf_of.into();
337        self
338    }
339}
340
341#[derive(Debug)]
342#[non_exhaustive]
343pub struct DisallowQueryingOptions<'a> {
344    pub bucket_name: Option<&'a str>,
345    pub scope_name: Option<&'a str>,
346    pub index_name: &'a str,
347    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
348}
349
350impl<'a> DisallowQueryingOptions<'a> {
351    pub fn new(index_name: &'a str) -> Self {
352        Self {
353            bucket_name: None,
354            scope_name: None,
355            index_name,
356            on_behalf_of: None,
357        }
358    }
359
360    pub fn bucket_name(mut self, bucket_name: impl Into<Option<&'a str>>) -> Self {
361        self.bucket_name = bucket_name.into();
362        self
363    }
364
365    pub fn scope_name(mut self, scope_name: impl Into<Option<&'a str>>) -> Self {
366        self.scope_name = scope_name.into();
367        self
368    }
369
370    pub fn on_behalf_of(mut self, on_behalf_of: impl Into<Option<&'a OnBehalfOfInfo>>) -> Self {
371        self.on_behalf_of = on_behalf_of.into();
372        self
373    }
374}
375
376#[derive(Debug)]
377#[non_exhaustive]
378pub struct FreezePlanOptions<'a> {
379    pub bucket_name: Option<&'a str>,
380    pub scope_name: Option<&'a str>,
381    pub index_name: &'a str,
382    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
383}
384
385impl<'a> FreezePlanOptions<'a> {
386    pub fn new(index_name: &'a str) -> Self {
387        Self {
388            bucket_name: None,
389            scope_name: None,
390            index_name,
391            on_behalf_of: None,
392        }
393    }
394
395    pub fn bucket_name(mut self, bucket_name: impl Into<Option<&'a str>>) -> Self {
396        self.bucket_name = bucket_name.into();
397        self
398    }
399
400    pub fn scope_name(mut self, scope_name: impl Into<Option<&'a str>>) -> Self {
401        self.scope_name = scope_name.into();
402        self
403    }
404
405    pub fn on_behalf_of(mut self, on_behalf_of: impl Into<Option<&'a OnBehalfOfInfo>>) -> Self {
406        self.on_behalf_of = on_behalf_of.into();
407        self
408    }
409}
410
411#[derive(Debug)]
412#[non_exhaustive]
413pub struct UnfreezePlanOptions<'a> {
414    pub bucket_name: Option<&'a str>,
415    pub scope_name: Option<&'a str>,
416    pub index_name: &'a str,
417    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
418}
419
420impl<'a> UnfreezePlanOptions<'a> {
421    pub fn new(index_name: &'a str) -> Self {
422        Self {
423            bucket_name: None,
424            scope_name: None,
425            index_name,
426            on_behalf_of: None,
427        }
428    }
429
430    pub fn bucket_name(mut self, bucket_name: impl Into<Option<&'a str>>) -> Self {
431        self.bucket_name = bucket_name.into();
432        self
433    }
434
435    pub fn scope_name(mut self, scope_name: impl Into<Option<&'a str>>) -> Self {
436        self.scope_name = scope_name.into();
437        self
438    }
439
440    pub fn on_behalf_of(mut self, on_behalf_of: impl Into<Option<&'a OnBehalfOfInfo>>) -> Self {
441        self.on_behalf_of = on_behalf_of.into();
442        self
443    }
444}
445
446#[derive(Default, Debug)]
447#[non_exhaustive]
448pub struct RefreshConfigOptions<'a> {
449    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
450}
451
452impl<'a> RefreshConfigOptions<'a> {
453    pub fn new() -> Self {
454        Self { on_behalf_of: None }
455    }
456    pub fn on_behalf_of(mut self, on_behalf_of: impl Into<Option<&'a OnBehalfOfInfo>>) -> Self {
457        self.on_behalf_of = on_behalf_of.into();
458        self
459    }
460}
461
462#[derive(Debug, Clone, Eq, PartialEq)]
463pub struct EnsureIndexPollOptions<C: Client> {
464    pub desired_state: DesiredState,
465    pub client: Arc<C>,
466    pub targets: Vec<NodeTarget>,
467}
468
469#[derive(Debug, Clone, Default)]
470#[non_exhaustive]
471pub struct PingOptions<'a> {
472    pub(crate) on_behalf_of: Option<&'a OnBehalfOfInfo>,
473}
474
475impl<'a> PingOptions<'a> {
476    pub fn new() -> Self {
477        Default::default()
478    }
479
480    pub fn on_behalf_of(mut self, on_behalf_of: impl Into<Option<&'a OnBehalfOfInfo>>) -> Self {
481        self.on_behalf_of = on_behalf_of.into();
482        self
483    }
484}