Skip to main content

mongodb/
search_index.rs

1use crate::bson::Document;
2
3use crate::bson::doc;
4use serde::{Deserialize, Serialize};
5use typed_builder::TypedBuilder;
6
7/// Specifies the options for a search index.
8#[serde_with::skip_serializing_none]
9#[derive(Debug, Clone, Default, TypedBuilder, Serialize, Deserialize)]
10#[builder(field_defaults(default, setter(into)))]
11#[non_exhaustive]
12pub struct SearchIndexModel {
13    /// The definition for this index.
14    pub definition: Document,
15
16    /// The name for this index, if present.
17    pub name: Option<String>,
18
19    /// The type for this index, if present.
20    #[serde(rename = "type")]
21    pub index_type: Option<SearchIndexType>,
22}
23
24/// Specifies the type of search index.
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(rename_all = "camelCase")]
27pub enum SearchIndexType {
28    /// A regular search index.
29    Search,
30    /// A vector search index.
31    VectorSearch,
32    /// An unknown type of search index.
33    #[serde(untagged)]
34    Other(String),
35}
36
37pub mod options {
38    #[cfg(docsrs)]
39    use crate::Collection;
40    use macro_magic::export_tokens;
41    use serde::Deserialize;
42    use typed_builder::TypedBuilder;
43
44    /// Options for [Collection::create_search_index].  Present to allow additional options to be
45    /// added in the future as a non-breaking change.
46    #[derive(Clone, Debug, Default, TypedBuilder, Deserialize)]
47    #[builder(field_defaults(default, setter(into)))]
48    #[non_exhaustive]
49    #[export_tokens]
50    pub struct CreateSearchIndexOptions {}
51
52    /// Options for [Collection::update_search_index].  Present to allow additional options to be
53    /// added in the future as a non-breaking change.
54    #[derive(Clone, Debug, Default, TypedBuilder, Deserialize)]
55    #[builder(field_defaults(default, setter(into)))]
56    #[non_exhaustive]
57    #[export_tokens]
58    pub struct UpdateSearchIndexOptions {}
59
60    /// Options for [Collection::list_search_indexes].  Present to allow additional options to be
61    /// added in the future as a non-breaking change.
62    #[derive(Clone, Debug, Default, TypedBuilder, Deserialize)]
63    #[builder(field_defaults(default, setter(into)))]
64    #[non_exhaustive]
65    #[export_tokens]
66    pub struct ListSearchIndexOptions {}
67
68    /// Options for [Collection::drop_search_index].  Present to allow additional options to be
69    /// added in the future as a non-breaking change.
70    #[derive(Clone, Debug, Default, TypedBuilder, Deserialize)]
71    #[builder(field_defaults(default, setter(into)))]
72    #[non_exhaustive]
73    #[export_tokens]
74    pub struct DropSearchIndexOptions {}
75}