1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use serde_json::Value;
#[derive(Debug, Clone, PartialEq, Serialize)]
pub enum TermsSetMinimumShouldMatch {
#[serde(rename = "minimum_should_match_field")]
Field(String),
#[serde(rename = "minimum_should_match_script")]
Script(TermsSetScript),
}
impl From<String> for TermsSetMinimumShouldMatch {
fn from(field: String) -> Self {
Self::Field(field)
}
}
impl<'a> From<&'a str> for TermsSetMinimumShouldMatch {
fn from(field: &'a str) -> Self {
Self::Field(field.to_string())
}
}
impl From<TermsSetScript> for TermsSetMinimumShouldMatch {
fn from(script: TermsSetScript) -> Self {
Self::Script(script)
}
}
#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct TermsSetScript {
source: String,
params: Option<Value>,
}
impl From<String> for TermsSetScript {
fn from(source: String) -> Self {
Self {
source,
params: None,
}
}
}
impl<'a> From<&'a str> for TermsSetScript {
fn from(source: &'a str) -> Self {
Self {
source: source.to_string(),
params: None,
}
}
}
impl TermsSetScript {
pub fn new(source: impl Into<String>) -> Self {
Self {
source: source.into(),
params: None,
}
}
pub fn params(mut self, params: Value) -> Self {
self.params = Some(params);
self
}
}