os_query_builder_rs/full_text/
multi_match.rs

1use serde::Serialize;
2use serde_json::Value;
3
4use crate::misc::fuzziness::Fuzziness;
5use crate::misc::operator::Operator;
6use crate::misc::r#type::Type;
7use crate::misc::zero_terms_query::ZeroTermsQuery;
8
9#[derive(Debug, Default, Clone, Serialize)]
10pub struct MultiMatch {
11    query: Option<Value>,
12
13    #[serde(skip_serializing_if = "Option::is_none")]
14    fields: Option<Vec<String>>,
15
16    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
17    query_type: Option<Type>,
18
19    #[serde(skip_serializing_if = "Option::is_none")]
20    operator: Option<Operator>,
21
22    #[serde(skip_serializing_if = "Option::is_none")]
23    minimum_should_match: Option<String>,
24
25    #[serde(skip_serializing_if = "Option::is_none")]
26    tie_breaker: Option<f64>,
27
28    #[serde(skip_serializing_if = "Option::is_none")]
29    analyzer: Option<String>,
30
31    #[serde(skip_serializing_if = "Option::is_none")]
32    boost: Option<f64>,
33
34    #[serde(skip_serializing_if = "Option::is_none")]
35    fuzziness: Option<Fuzziness>,
36
37    #[serde(skip_serializing_if = "Option::is_none")]
38    fuzzy_transpositions: Option<bool>,
39
40    #[serde(skip_serializing_if = "Option::is_none")]
41    lenient: Option<bool>,
42
43    #[serde(skip_serializing_if = "Option::is_none")]
44    prefix_length: Option<u64>,
45
46    #[serde(skip_serializing_if = "Option::is_none")]
47    max_expansions: Option<u64>,
48
49    #[serde(skip_serializing_if = "Option::is_none")]
50    auto_generate_synonyms_phrase_query: Option<bool>,
51
52    #[serde(skip_serializing_if = "Option::is_none")]
53    zero_terms_query: Option<ZeroTermsQuery>,
54}
55
56impl MultiMatch {
57    pub fn new() -> Self {
58        Self::default()
59    }
60
61    pub fn fields<F, T>(self, fields: F) -> Self
62        where
63            F: IntoIterator<Item=T>,
64            T: Into<String>,
65    {
66
67        Self {
68            fields: Some(
69                fields
70                    .into_iter()
71                    .map(|f| f.into())
72                    .collect()
73            ),
74            ..self
75        }
76    }
77
78    pub fn value<T: Into<Value>>(self, value: T) -> Self {
79        Self {
80            query: Some(value.into()),
81            ..self
82        }
83    }
84
85    pub fn query<T: Into<Value>>(self, query: T) -> Self {
86        self.value(query)
87    }
88
89    pub fn query_type<T: Into<Type>>(self, typ: T) -> Self {
90        Self {
91            query_type: Some(typ.into()),
92            ..self
93        }
94    }
95
96    pub fn operator<T: Into<Operator>>(self, operator: T) -> Self {
97        Self {
98            operator: Some(operator.into()),
99            ..self
100        }
101    }
102
103    pub fn minimum_should_match<T: Into<String>>(self, minimum_should_match: T) -> Self {
104        Self {
105            minimum_should_match: Some(minimum_should_match.into()),
106            ..self
107        }
108    }
109
110    pub fn tie_breaker<T: Into<f64>>(self, tie_breaker: T) -> Self {
111        Self {
112            tie_breaker: Some(tie_breaker.into()),
113            ..self
114        }
115    }
116
117    pub fn analyzer<T: Into<String>>(self, analyzer: T) -> Self {
118        Self {
119            analyzer: Some(analyzer.into()),
120            ..self
121        }
122    }
123
124    pub fn boost<T: Into<f64>>(self, boost: T) -> Self {
125        Self {
126            boost: Some(boost.into()),
127            ..self
128        }
129    }
130
131    pub fn fuzziness<T: Into<Fuzziness>>(self, fuzziness: T) -> Self {
132        Self {
133            fuzziness: Some(fuzziness.into()),
134            ..self
135        }
136    }
137
138    pub fn fuzzy_transpositions(self, fuzzy_transpositions: bool) -> Self {
139        Self {
140            fuzzy_transpositions: Some(fuzzy_transpositions),
141            ..self
142        }
143    }
144
145    pub fn lenient(self, lenient: bool) -> Self {
146        Self {
147            lenient: Some(lenient),
148            ..self
149        }
150    }
151
152    pub fn prefix_length<T: Into<u64>>(self, prefix_length: T) -> Self {
153        Self {
154            prefix_length: Some(prefix_length.into()),
155            ..self
156        }
157    }
158
159    pub fn max_expansions<T: Into<u64>>(self, max_expansions: T) -> Self {
160        Self {
161            max_expansions: Some(max_expansions.into()),
162            ..self
163        }
164    }
165
166    pub fn auto_generate_synonyms_phrase_query(
167        self,
168        auto_generate_synonyms_phrase_query: bool,
169    ) -> Self {
170        Self {
171            auto_generate_synonyms_phrase_query: Some(auto_generate_synonyms_phrase_query),
172            ..self
173        }
174    }
175
176    pub fn zero_terms_query<T: Into<ZeroTermsQuery>>(self, zero_terms_query: T) -> Self {
177        Self {
178            zero_terms_query: Some(zero_terms_query.into()),
179            ..self
180        }
181    }
182}