Skip to main content

nominal_api/conjure/objects/scout/internal/search/api/
search_query.rs

1use conjure_object::serde::{ser, de};
2use conjure_object::serde::ser::SerializeMap as SerializeMap_;
3use conjure_object::private::{UnionField_, UnionTypeField_};
4use std::fmt;
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
6pub enum SearchQuery {
7    DateTimeField(super::DateTimeField),
8    StringField(super::StringField),
9    TimestampField(super::TimestampField),
10    LongField(super::LongField),
11    BooleanField(super::BooleanField),
12    /// Performs case insensitive exact match search on the title.
13    ExactMatch(String),
14    /// Requires the string values in the query to exactly match the set of string values in the resource.
15    /// To do a partial match, use an "and" on StringField queries.
16    StringArrayExactMatch(super::StringArrayField),
17    StringArrayLength(super::super::super::super::metadata::StringArrayLengthQuery),
18    SearchText(String),
19    Label(super::super::super::super::super::api::Label),
20    Property(super::super::super::super::super::api::Property),
21    /// Matches documents that have a property with this key, regardless of value.
22    PropertyKey(super::super::super::super::super::api::PropertyName),
23    /// Matches documents that have a value for the given datetime field name.
24    DateTimeFieldPresent(String),
25    And(Vec<super::SearchQuery>),
26    Or(Vec<super::SearchQuery>),
27    Not(Box<super::SearchQuery>),
28    Workspace(super::super::super::super::super::api::rids::WorkspaceRid),
29    CreatedAt(super::super::super::super::metadata::CreatedAtQuery),
30    /// Prefer to use archivedStatus field in IndexableDb#search
31    ArchivedStatus(super::super::super::super::super::api::ArchivedStatus),
32    IsPublished(bool),
33    /// An unknown variant.
34    Unknown(Unknown),
35}
36impl ser::Serialize for SearchQuery {
37    fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
38    where
39        S: ser::Serializer,
40    {
41        let mut map = s.serialize_map(Some(2))?;
42        match self {
43            SearchQuery::DateTimeField(value) => {
44                map.serialize_entry(&"type", &"dateTimeField")?;
45                map.serialize_entry(&"dateTimeField", value)?;
46            }
47            SearchQuery::StringField(value) => {
48                map.serialize_entry(&"type", &"stringField")?;
49                map.serialize_entry(&"stringField", value)?;
50            }
51            SearchQuery::TimestampField(value) => {
52                map.serialize_entry(&"type", &"timestampField")?;
53                map.serialize_entry(&"timestampField", value)?;
54            }
55            SearchQuery::LongField(value) => {
56                map.serialize_entry(&"type", &"longField")?;
57                map.serialize_entry(&"longField", value)?;
58            }
59            SearchQuery::BooleanField(value) => {
60                map.serialize_entry(&"type", &"booleanField")?;
61                map.serialize_entry(&"booleanField", value)?;
62            }
63            SearchQuery::ExactMatch(value) => {
64                map.serialize_entry(&"type", &"exactMatch")?;
65                map.serialize_entry(&"exactMatch", value)?;
66            }
67            SearchQuery::StringArrayExactMatch(value) => {
68                map.serialize_entry(&"type", &"stringArrayExactMatch")?;
69                map.serialize_entry(&"stringArrayExactMatch", value)?;
70            }
71            SearchQuery::StringArrayLength(value) => {
72                map.serialize_entry(&"type", &"stringArrayLength")?;
73                map.serialize_entry(&"stringArrayLength", value)?;
74            }
75            SearchQuery::SearchText(value) => {
76                map.serialize_entry(&"type", &"searchText")?;
77                map.serialize_entry(&"searchText", value)?;
78            }
79            SearchQuery::Label(value) => {
80                map.serialize_entry(&"type", &"label")?;
81                map.serialize_entry(&"label", value)?;
82            }
83            SearchQuery::Property(value) => {
84                map.serialize_entry(&"type", &"property")?;
85                map.serialize_entry(&"property", value)?;
86            }
87            SearchQuery::PropertyKey(value) => {
88                map.serialize_entry(&"type", &"propertyKey")?;
89                map.serialize_entry(&"propertyKey", value)?;
90            }
91            SearchQuery::DateTimeFieldPresent(value) => {
92                map.serialize_entry(&"type", &"dateTimeFieldPresent")?;
93                map.serialize_entry(&"dateTimeFieldPresent", value)?;
94            }
95            SearchQuery::And(value) => {
96                map.serialize_entry(&"type", &"and")?;
97                map.serialize_entry(&"and", value)?;
98            }
99            SearchQuery::Or(value) => {
100                map.serialize_entry(&"type", &"or")?;
101                map.serialize_entry(&"or", value)?;
102            }
103            SearchQuery::Not(value) => {
104                map.serialize_entry(&"type", &"not")?;
105                map.serialize_entry(&"not", value)?;
106            }
107            SearchQuery::Workspace(value) => {
108                map.serialize_entry(&"type", &"workspace")?;
109                map.serialize_entry(&"workspace", value)?;
110            }
111            SearchQuery::CreatedAt(value) => {
112                map.serialize_entry(&"type", &"createdAt")?;
113                map.serialize_entry(&"createdAt", value)?;
114            }
115            SearchQuery::ArchivedStatus(value) => {
116                map.serialize_entry(&"type", &"archivedStatus")?;
117                map.serialize_entry(&"archivedStatus", value)?;
118            }
119            SearchQuery::IsPublished(value) => {
120                map.serialize_entry(&"type", &"isPublished")?;
121                map.serialize_entry(&"isPublished", value)?;
122            }
123            SearchQuery::Unknown(value) => {
124                map.serialize_entry(&"type", &value.type_)?;
125                map.serialize_entry(&value.type_, &value.value)?;
126            }
127        }
128        map.end()
129    }
130}
131impl<'de> de::Deserialize<'de> for SearchQuery {
132    fn deserialize<D>(d: D) -> Result<SearchQuery, D::Error>
133    where
134        D: de::Deserializer<'de>,
135    {
136        d.deserialize_map(Visitor_)
137    }
138}
139struct Visitor_;
140impl<'de> de::Visitor<'de> for Visitor_ {
141    type Value = SearchQuery;
142    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
143        fmt.write_str("union SearchQuery")
144    }
145    fn visit_map<A>(self, mut map: A) -> Result<SearchQuery, A::Error>
146    where
147        A: de::MapAccess<'de>,
148    {
149        let v = match map.next_key::<UnionField_<Variant_>>()? {
150            Some(UnionField_::Type) => {
151                let variant = map.next_value()?;
152                let key = map.next_key()?;
153                match (variant, key) {
154                    (Variant_::DateTimeField, Some(Variant_::DateTimeField)) => {
155                        let value = map.next_value()?;
156                        SearchQuery::DateTimeField(value)
157                    }
158                    (Variant_::StringField, Some(Variant_::StringField)) => {
159                        let value = map.next_value()?;
160                        SearchQuery::StringField(value)
161                    }
162                    (Variant_::TimestampField, Some(Variant_::TimestampField)) => {
163                        let value = map.next_value()?;
164                        SearchQuery::TimestampField(value)
165                    }
166                    (Variant_::LongField, Some(Variant_::LongField)) => {
167                        let value = map.next_value()?;
168                        SearchQuery::LongField(value)
169                    }
170                    (Variant_::BooleanField, Some(Variant_::BooleanField)) => {
171                        let value = map.next_value()?;
172                        SearchQuery::BooleanField(value)
173                    }
174                    (Variant_::ExactMatch, Some(Variant_::ExactMatch)) => {
175                        let value = map.next_value()?;
176                        SearchQuery::ExactMatch(value)
177                    }
178                    (
179                        Variant_::StringArrayExactMatch,
180                        Some(Variant_::StringArrayExactMatch),
181                    ) => {
182                        let value = map.next_value()?;
183                        SearchQuery::StringArrayExactMatch(value)
184                    }
185                    (Variant_::StringArrayLength, Some(Variant_::StringArrayLength)) => {
186                        let value = map.next_value()?;
187                        SearchQuery::StringArrayLength(value)
188                    }
189                    (Variant_::SearchText, Some(Variant_::SearchText)) => {
190                        let value = map.next_value()?;
191                        SearchQuery::SearchText(value)
192                    }
193                    (Variant_::Label, Some(Variant_::Label)) => {
194                        let value = map.next_value()?;
195                        SearchQuery::Label(value)
196                    }
197                    (Variant_::Property, Some(Variant_::Property)) => {
198                        let value = map.next_value()?;
199                        SearchQuery::Property(value)
200                    }
201                    (Variant_::PropertyKey, Some(Variant_::PropertyKey)) => {
202                        let value = map.next_value()?;
203                        SearchQuery::PropertyKey(value)
204                    }
205                    (
206                        Variant_::DateTimeFieldPresent,
207                        Some(Variant_::DateTimeFieldPresent),
208                    ) => {
209                        let value = map.next_value()?;
210                        SearchQuery::DateTimeFieldPresent(value)
211                    }
212                    (Variant_::And, Some(Variant_::And)) => {
213                        let value = map.next_value()?;
214                        SearchQuery::And(value)
215                    }
216                    (Variant_::Or, Some(Variant_::Or)) => {
217                        let value = map.next_value()?;
218                        SearchQuery::Or(value)
219                    }
220                    (Variant_::Not, Some(Variant_::Not)) => {
221                        let value = map.next_value()?;
222                        SearchQuery::Not(value)
223                    }
224                    (Variant_::Workspace, Some(Variant_::Workspace)) => {
225                        let value = map.next_value()?;
226                        SearchQuery::Workspace(value)
227                    }
228                    (Variant_::CreatedAt, Some(Variant_::CreatedAt)) => {
229                        let value = map.next_value()?;
230                        SearchQuery::CreatedAt(value)
231                    }
232                    (Variant_::ArchivedStatus, Some(Variant_::ArchivedStatus)) => {
233                        let value = map.next_value()?;
234                        SearchQuery::ArchivedStatus(value)
235                    }
236                    (Variant_::IsPublished, Some(Variant_::IsPublished)) => {
237                        let value = map.next_value()?;
238                        SearchQuery::IsPublished(value)
239                    }
240                    (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
241                        if type_ == b {
242                            let value = map.next_value()?;
243                            SearchQuery::Unknown(Unknown { type_, value })
244                        } else {
245                            return Err(
246                                de::Error::invalid_value(de::Unexpected::Str(&type_), &&*b),
247                            )
248                        }
249                    }
250                    (variant, Some(key)) => {
251                        return Err(
252                            de::Error::invalid_value(
253                                de::Unexpected::Str(key.as_str()),
254                                &variant.as_str(),
255                            ),
256                        );
257                    }
258                    (variant, None) => {
259                        return Err(de::Error::missing_field(variant.as_str()));
260                    }
261                }
262            }
263            Some(UnionField_::Value(variant)) => {
264                let value = match &variant {
265                    Variant_::DateTimeField => {
266                        let value = map.next_value()?;
267                        SearchQuery::DateTimeField(value)
268                    }
269                    Variant_::StringField => {
270                        let value = map.next_value()?;
271                        SearchQuery::StringField(value)
272                    }
273                    Variant_::TimestampField => {
274                        let value = map.next_value()?;
275                        SearchQuery::TimestampField(value)
276                    }
277                    Variant_::LongField => {
278                        let value = map.next_value()?;
279                        SearchQuery::LongField(value)
280                    }
281                    Variant_::BooleanField => {
282                        let value = map.next_value()?;
283                        SearchQuery::BooleanField(value)
284                    }
285                    Variant_::ExactMatch => {
286                        let value = map.next_value()?;
287                        SearchQuery::ExactMatch(value)
288                    }
289                    Variant_::StringArrayExactMatch => {
290                        let value = map.next_value()?;
291                        SearchQuery::StringArrayExactMatch(value)
292                    }
293                    Variant_::StringArrayLength => {
294                        let value = map.next_value()?;
295                        SearchQuery::StringArrayLength(value)
296                    }
297                    Variant_::SearchText => {
298                        let value = map.next_value()?;
299                        SearchQuery::SearchText(value)
300                    }
301                    Variant_::Label => {
302                        let value = map.next_value()?;
303                        SearchQuery::Label(value)
304                    }
305                    Variant_::Property => {
306                        let value = map.next_value()?;
307                        SearchQuery::Property(value)
308                    }
309                    Variant_::PropertyKey => {
310                        let value = map.next_value()?;
311                        SearchQuery::PropertyKey(value)
312                    }
313                    Variant_::DateTimeFieldPresent => {
314                        let value = map.next_value()?;
315                        SearchQuery::DateTimeFieldPresent(value)
316                    }
317                    Variant_::And => {
318                        let value = map.next_value()?;
319                        SearchQuery::And(value)
320                    }
321                    Variant_::Or => {
322                        let value = map.next_value()?;
323                        SearchQuery::Or(value)
324                    }
325                    Variant_::Not => {
326                        let value = map.next_value()?;
327                        SearchQuery::Not(value)
328                    }
329                    Variant_::Workspace => {
330                        let value = map.next_value()?;
331                        SearchQuery::Workspace(value)
332                    }
333                    Variant_::CreatedAt => {
334                        let value = map.next_value()?;
335                        SearchQuery::CreatedAt(value)
336                    }
337                    Variant_::ArchivedStatus => {
338                        let value = map.next_value()?;
339                        SearchQuery::ArchivedStatus(value)
340                    }
341                    Variant_::IsPublished => {
342                        let value = map.next_value()?;
343                        SearchQuery::IsPublished(value)
344                    }
345                    Variant_::Unknown(type_) => {
346                        let value = map.next_value()?;
347                        SearchQuery::Unknown(Unknown {
348                            type_: type_.clone(),
349                            value,
350                        })
351                    }
352                };
353                if map.next_key::<UnionTypeField_>()?.is_none() {
354                    return Err(de::Error::missing_field("type"));
355                }
356                let type_variant = map.next_value::<Variant_>()?;
357                if variant != type_variant {
358                    return Err(
359                        de::Error::invalid_value(
360                            de::Unexpected::Str(type_variant.as_str()),
361                            &variant.as_str(),
362                        ),
363                    );
364                }
365                value
366            }
367            None => return Err(de::Error::missing_field("type")),
368        };
369        if map.next_key::<UnionField_<Variant_>>()?.is_some() {
370            return Err(de::Error::invalid_length(3, &"type and value fields"));
371        }
372        Ok(v)
373    }
374}
375#[derive(PartialEq)]
376enum Variant_ {
377    DateTimeField,
378    StringField,
379    TimestampField,
380    LongField,
381    BooleanField,
382    ExactMatch,
383    StringArrayExactMatch,
384    StringArrayLength,
385    SearchText,
386    Label,
387    Property,
388    PropertyKey,
389    DateTimeFieldPresent,
390    And,
391    Or,
392    Not,
393    Workspace,
394    CreatedAt,
395    ArchivedStatus,
396    IsPublished,
397    Unknown(Box<str>),
398}
399impl Variant_ {
400    fn as_str(&self) -> &'static str {
401        match *self {
402            Variant_::DateTimeField => "dateTimeField",
403            Variant_::StringField => "stringField",
404            Variant_::TimestampField => "timestampField",
405            Variant_::LongField => "longField",
406            Variant_::BooleanField => "booleanField",
407            Variant_::ExactMatch => "exactMatch",
408            Variant_::StringArrayExactMatch => "stringArrayExactMatch",
409            Variant_::StringArrayLength => "stringArrayLength",
410            Variant_::SearchText => "searchText",
411            Variant_::Label => "label",
412            Variant_::Property => "property",
413            Variant_::PropertyKey => "propertyKey",
414            Variant_::DateTimeFieldPresent => "dateTimeFieldPresent",
415            Variant_::And => "and",
416            Variant_::Or => "or",
417            Variant_::Not => "not",
418            Variant_::Workspace => "workspace",
419            Variant_::CreatedAt => "createdAt",
420            Variant_::ArchivedStatus => "archivedStatus",
421            Variant_::IsPublished => "isPublished",
422            Variant_::Unknown(_) => "unknown variant",
423        }
424    }
425}
426impl<'de> de::Deserialize<'de> for Variant_ {
427    fn deserialize<D>(d: D) -> Result<Variant_, D::Error>
428    where
429        D: de::Deserializer<'de>,
430    {
431        d.deserialize_str(VariantVisitor_)
432    }
433}
434struct VariantVisitor_;
435impl<'de> de::Visitor<'de> for VariantVisitor_ {
436    type Value = Variant_;
437    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
438        fmt.write_str("string")
439    }
440    fn visit_str<E>(self, value: &str) -> Result<Variant_, E>
441    where
442        E: de::Error,
443    {
444        let v = match value {
445            "dateTimeField" => Variant_::DateTimeField,
446            "stringField" => Variant_::StringField,
447            "timestampField" => Variant_::TimestampField,
448            "longField" => Variant_::LongField,
449            "booleanField" => Variant_::BooleanField,
450            "exactMatch" => Variant_::ExactMatch,
451            "stringArrayExactMatch" => Variant_::StringArrayExactMatch,
452            "stringArrayLength" => Variant_::StringArrayLength,
453            "searchText" => Variant_::SearchText,
454            "label" => Variant_::Label,
455            "property" => Variant_::Property,
456            "propertyKey" => Variant_::PropertyKey,
457            "dateTimeFieldPresent" => Variant_::DateTimeFieldPresent,
458            "and" => Variant_::And,
459            "or" => Variant_::Or,
460            "not" => Variant_::Not,
461            "workspace" => Variant_::Workspace,
462            "createdAt" => Variant_::CreatedAt,
463            "archivedStatus" => Variant_::ArchivedStatus,
464            "isPublished" => Variant_::IsPublished,
465            value => Variant_::Unknown(value.to_string().into_boxed_str()),
466        };
467        Ok(v)
468    }
469}
470///An unknown variant of the SearchQuery union.
471#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
472pub struct Unknown {
473    type_: Box<str>,
474    value: conjure_object::Any,
475}
476impl Unknown {
477    /// Returns the unknown variant's type name.
478    #[inline]
479    pub fn type_(&self) -> &str {
480        &self.type_
481    }
482}