1use serde_json::Value;
10
11#[derive(Debug, Clone, Copy)]
13pub enum Operator {
14 And,
16 Or,
18}
19
20impl Operator {
21 pub(crate) fn as_str(self) -> &'static str {
22 match self {
23 Operator::And => "AND",
24 Operator::Or => "OR",
25 }
26 }
27}
28
29#[derive(Debug, Clone, Copy)]
31pub enum ScoreMode {
32 Multiply,
34 Sum,
36 Avg,
38 First,
40 Max,
42 Min,
44}
45
46impl ScoreMode {
47 pub(crate) fn as_str(self) -> &'static str {
48 match self {
49 ScoreMode::Multiply => "multiply",
50 ScoreMode::Sum => "sum",
51 ScoreMode::Avg => "avg",
52 ScoreMode::First => "first",
53 ScoreMode::Max => "max",
54 ScoreMode::Min => "min",
55 }
56 }
57}
58
59#[derive(Debug, Clone, Copy)]
63pub enum NestedScoreMode {
64 Avg,
66 Sum,
68 Min,
70 Max,
72 None,
74}
75
76impl NestedScoreMode {
77 pub(crate) fn as_str(self) -> &'static str {
78 match self {
79 NestedScoreMode::Avg => "avg",
80 NestedScoreMode::Sum => "sum",
81 NestedScoreMode::Min => "min",
82 NestedScoreMode::Max => "max",
83 NestedScoreMode::None => "none",
84 }
85 }
86}
87
88#[derive(Debug, Clone, Copy)]
90pub enum BoostMode {
91 Multiply,
93 Replace,
95 Sum,
97 Avg,
99 Max,
101 Min,
103}
104
105impl BoostMode {
106 pub(crate) fn as_str(self) -> &'static str {
107 match self {
108 BoostMode::Multiply => "multiply",
109 BoostMode::Replace => "replace",
110 BoostMode::Sum => "sum",
111 BoostMode::Avg => "avg",
112 BoostMode::Max => "max",
113 BoostMode::Min => "min",
114 }
115 }
116}
117
118#[derive(Debug, Clone, Copy)]
120pub enum ZeroTermsQuery {
121 None,
123 All,
125}
126
127impl ZeroTermsQuery {
128 pub(crate) fn as_str(self) -> &'static str {
129 match self {
130 ZeroTermsQuery::None => "none",
131 ZeroTermsQuery::All => "all",
132 }
133 }
134}
135
136#[derive(Debug, Clone, Copy)]
138pub enum RangeRelation {
139 Intersects,
141 Contains,
143 Within,
145}
146
147impl RangeRelation {
148 pub(crate) fn as_str(self) -> &'static str {
149 match self {
150 RangeRelation::Intersects => "INTERSECTS",
151 RangeRelation::Contains => "CONTAINS",
152 RangeRelation::Within => "WITHIN",
153 }
154 }
155}
156
157#[derive(Debug, Clone, Copy)]
159pub enum MultiMatchType {
160 BestFields,
162 MostFields,
164 CrossFields,
166 Phrase,
168 PhrasePrefix,
170 BoolPrefix,
172}
173
174impl MultiMatchType {
175 pub(crate) fn as_str(self) -> &'static str {
176 match self {
177 MultiMatchType::BestFields => "best_fields",
178 MultiMatchType::MostFields => "most_fields",
179 MultiMatchType::CrossFields => "cross_fields",
180 MultiMatchType::Phrase => "phrase",
181 MultiMatchType::PhrasePrefix => "phrase_prefix",
182 MultiMatchType::BoolPrefix => "bool_prefix",
183 }
184 }
185}
186
187#[derive(Debug, Clone)]
194pub enum MinimumShouldMatch {
195 Count(i32),
197 Percent(i32),
199 Raw(String),
201}
202
203impl MinimumShouldMatch {
204 pub fn count(n: i32) -> Self {
206 Self::Count(n)
207 }
208
209 pub fn percent(p: i32) -> Self {
211 Self::Percent(p)
212 }
213
214 pub fn raw(expr: impl Into<String>) -> Self {
216 Self::Raw(expr.into())
217 }
218
219 pub(crate) fn to_value(&self) -> Value {
220 match self {
221 MinimumShouldMatch::Count(n) => Value::from(*n),
222 MinimumShouldMatch::Percent(p) => Value::String(format!("{p}%")),
223 MinimumShouldMatch::Raw(expr) => Value::String(expr.clone()),
224 }
225 }
226}
227
228impl From<i32> for MinimumShouldMatch {
229 fn from(n: i32) -> Self {
230 MinimumShouldMatch::Count(n)
231 }
232}
233
234#[derive(Debug, Clone, Copy)]
236pub enum DistanceType {
237 Arc,
239 Plane,
241}
242
243impl DistanceType {
244 pub(crate) fn as_str(self) -> &'static str {
245 match self {
246 DistanceType::Arc => "arc",
247 DistanceType::Plane => "plane",
248 }
249 }
250}
251
252#[derive(Debug, Clone, Copy)]
254pub enum ValidationMethod {
255 Strict,
257 Coerce,
259 IgnoreMalformed,
261}
262
263impl ValidationMethod {
264 pub(crate) fn as_str(self) -> &'static str {
265 match self {
266 ValidationMethod::Strict => "STRICT",
267 ValidationMethod::Coerce => "COERCE",
268 ValidationMethod::IgnoreMalformed => "IGNORE_MALFORMED",
269 }
270 }
271}
272
273#[derive(Debug, Clone, Copy)]
275pub enum NumericType {
276 Double,
278 Long,
280 Date,
282 DateNanos,
284}
285
286impl NumericType {
287 pub(crate) fn as_str(self) -> &'static str {
288 match self {
289 NumericType::Double => "double",
290 NumericType::Long => "long",
291 NumericType::Date => "date",
292 NumericType::DateNanos => "date_nanos",
293 }
294 }
295}
296
297#[derive(Debug, Clone, Copy)]
299pub enum ScriptSortType {
300 Number,
302 String,
304}
305
306impl ScriptSortType {
307 pub(crate) fn as_str(self) -> &'static str {
308 match self {
309 ScriptSortType::Number => "number",
310 ScriptSortType::String => "string",
311 }
312 }
313}
314
315#[derive(Debug, Clone, Copy)]
317pub enum Fuzziness {
318 Auto,
320 AutoBounds(u32, u32),
322 Edits(u32),
324}
325
326impl Fuzziness {
327 pub(crate) fn to_value(self) -> Value {
328 match self {
329 Fuzziness::Auto => Value::String("AUTO".to_string()),
330 Fuzziness::AutoBounds(lo, hi) => Value::String(format!("AUTO:{lo}:{hi}")),
331 Fuzziness::Edits(edits) => Value::from(edits),
332 }
333 }
334}