elasticsearch_dsl/search/queries/params/
terms_set_query.rs

1use serde_json::Value;
2
3/// Number of matching terms to be required
4#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
5pub enum TermsSetMinimumShouldMatch {
6    /// [Numeric](https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html)
7    /// field containing the number of matching terms required to return a document.
8    #[serde(rename = "minimum_should_match_field")]
9    Field(String),
10
11    /// Custom script containing the number of matching terms required to return a document.
12    ///
13    /// For parameters and valid values, see
14    /// [Scripting](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html).
15    ///
16    /// For an example query using the `minimum_should_match_script` parameter, see
17    /// [How to use the `minimum_should_match_script` parameter](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-set-query.html#terms-set-query-script).
18    #[serde(rename = "minimum_should_match_script")]
19    Script(TermsSetScript),
20}
21
22impl From<String> for TermsSetMinimumShouldMatch {
23    fn from(field: String) -> Self {
24        Self::Field(field)
25    }
26}
27
28impl<'a> From<&'a str> for TermsSetMinimumShouldMatch {
29    fn from(field: &'a str) -> Self {
30        Self::Field(field.to_string())
31    }
32}
33
34impl From<TermsSetScript> for TermsSetMinimumShouldMatch {
35    fn from(script: TermsSetScript) -> Self {
36        Self::Script(script)
37    }
38}
39
40/// Custom script containing the number of matching terms required to return a document.
41///
42/// For parameters and valid values, see
43/// [Scripting](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html).
44#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
45pub struct TermsSetScript {
46    source: String,
47    params: Option<Value>,
48}
49
50impl From<String> for TermsSetScript {
51    fn from(source: String) -> Self {
52        Self {
53            source,
54            params: None,
55        }
56    }
57}
58
59impl<'a> From<&'a str> for TermsSetScript {
60    fn from(source: &'a str) -> Self {
61        Self {
62            source: source.to_string(),
63            params: None,
64        }
65    }
66}
67
68impl TermsSetScript {
69    /// Creates an instance of [TermsSetScript]
70    pub fn new<T>(source: T) -> Self
71    where
72        T: ToString,
73    {
74        Self {
75            source: source.to_string(),
76            params: None,
77        }
78    }
79
80    /// Assign params
81    pub fn params(mut self, params: Value) -> Self {
82        self.params = Some(params);
83        self
84    }
85}