os_query_builder_rs/misc/
query_field.rs

1use serde::Serialize;
2use crate::compound_query::{
3    bool::Bool,
4    boosting::Boosting,
5    constant_score::ConstantScore,
6    disjunction_max::DisMax
7};
8use crate::full_text::{
9    match_boolean_prefix::MatchBoolPrefix,
10    match_phrase::MatchPhrase,
11    match_phrase_prefix::MatchPhrasePrefix,
12    multi_match::MultiMatch,
13    query_string::QueryString,
14    r#match::Match,
15    simple_query_string::SimpleQueryString,
16    intervals::interval::Intervals
17};
18use crate::term::{
19    exists::Exists,
20    fuzzy::Fuzzy,
21    ids::IDs,
22    prefix::Prefix,
23    range::Range,
24    regexp::Regexp,
25    term::Term,
26    terms::Terms,
27    terms_set::TermsSet,
28    wildcard::Wildcard
29};
30
31#[derive(Debug, Clone, Serialize)]
32#[serde(rename_all = "snake_case")]
33pub enum QueryField {
34    /// https://opensearch.org/docs/latest/query-dsl/full-text/match/
35    Match(Match),
36    /// https://opensearch.org/docs/latest/query-dsl/full-text/multi-match/
37    MultiMatch(MultiMatch),
38    /// https://opensearch.org/docs/latest/query-dsl/full-text/query-string/
39    QueryString(QueryString),
40    /// https://opensearch.org/docs/latest/query-dsl/full-text/simple-query-string/
41    SimpleQueryString(SimpleQueryString),
42    /// https://opensearch.org/docs/latest/query-dsl/full-text/match-phrase/
43    MatchPhrase(MatchPhrase),
44    /// https://opensearch.org/docs/latest/query-dsl/full-text/match-phrase-prefix/
45    MatchPhrasePrefix(MatchPhrasePrefix),
46    /// https://opensearch.org/docs/latest/query-dsl/full-text/match-bool-prefix/
47    MatchBoolPrefix(MatchBoolPrefix),
48    /// https://opensearch.org/docs/latest/query-dsl/full-text/intervals/
49    Intervals(Intervals),
50    /// https://opensearch.org/docs/latest/query-dsl/term/terms/
51    /// https://opensearch.org/docs/latest/query-dsl/term/terms/#terms-lookup
52    Terms(Terms),
53    /// https://opensearch.org/docs/latest/query-dsl/term/term/
54    Term(Term),
55    /// https://opensearch.org/docs/latest/query-dsl/term/terms-set/
56    TermsSet(TermsSet),
57    /// https://opensearch.org/docs/latest/query-dsl/compound/bool/
58    Bool(Bool),
59    /// https://opensearch.org/docs/latest/query-dsl/compound/boosting/
60    Boosting(Boosting),
61    /// https://opensearch.org/docs/latest/query-dsl/compound/constant-score/
62    ConstantScore(ConstantScore),
63    /// https://opensearch.org/docs/latest/query-dsl/compound/disjunction-max/
64    DisMax(DisMax),
65    /// https://opensearch.org/docs/latest/query-dsl/term/wildcard/
66    Wildcard(Wildcard),
67    /// https://opensearch.org/docs/latest/query-dsl/term/ids/
68    #[serde(rename="ids")]
69    IDs(IDs),
70    /// https://opensearch.org/docs/latest/query-dsl/term/ids/
71    Fuzzy(Fuzzy),
72    /// https://opensearch.org/docs/latest/query-dsl/term/prefix/
73    Prefix(Prefix),
74    /// https://opensearch.org/docs/latest/query-dsl/term/regexp/
75    Regexp(Regexp),
76    ///https://opensearch.org/docs/latest/query-dsl/term/exists/
77    Exists(Exists),
78    /// https://opensearch.org/docs/latest/query-dsl/term/range/
79    Range(Range),
80}
81
82macro_rules! from_types {
83    ($($ty:ident),*) => {
84        $(
85            impl From<$ty> for QueryField {
86                fn from(val: $ty) -> Self {
87                    Self::$ty(val.into())
88                }
89            }
90        )*
91    }
92}
93
94from_types! {
95    Match,
96    MultiMatch,
97    QueryString,
98    SimpleQueryString,
99    MatchPhrase,
100    MatchPhrasePrefix,
101    MatchBoolPrefix,
102    Terms,
103    Term,
104    TermsSet,
105    Bool,
106    Boosting,
107    ConstantScore,
108    DisMax,
109    Wildcard,
110    IDs,
111    Fuzzy,
112    Prefix,
113    Regexp,
114    Exists,
115    Range,
116    Intervals
117}