elasticsearch_dsl/search/queries/params/
simple_query_string_query.rs

1use serde::ser::{Serialize, Serializer};
2
3/// You can use the flags parameter to enable more optional operators for Lucene’s regular
4/// expression engine.
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
6pub enum SimpleQueryStringQueryFlags {
7    /// Enables all optional operators.
8    All,
9
10    /// Enables the `+` AND operator.
11    And,
12
13    /// Enables `\` as an escape character.
14    Escape,
15
16    /// Enables the `~N` operator after a word, where `N` is an integer
17    /// denoting the allowed edit distance for matching. See
18    /// [Fuzziness](https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#fuzziness).
19    Fuzzy,
20
21    /// Enables the `~N` operator, after a phrase where `N` is the maximum
22    /// number of positions allowed between matching tokens. Synonymous to
23    /// [SLOP](SimpleQueryStringQueryFlags::Slop).
24    Near,
25
26    /// Disables all operators.
27    None,
28
29    /// Enables the `-` NOT operator.
30    Not,
31
32    /// Enables the `\|` OR operator.
33    Or,
34
35    /// Enables the `"` quotes operator used to search for phrases.
36    Phrase,
37
38    /// Enables the `(` and `)` operators to control operator precedence.
39    Precedence,
40
41    /// Enables the `*` prefix operator.
42    Prefix,
43
44    /// Enables the `~N` operator, after a phrase where `N` is maximum
45    /// number of positions allowed between matching tokens. Synonymous to
46    /// [NEAR](SimpleQueryStringQueryFlags::Near).
47    Slop,
48
49    /// Enables whitespace as split characters.
50    Whitespace,
51}
52
53impl From<SimpleQueryStringQueryFlags> for &'static str {
54    fn from(value: SimpleQueryStringQueryFlags) -> Self {
55        match value {
56            SimpleQueryStringQueryFlags::All => "ALL",
57            SimpleQueryStringQueryFlags::And => "AND",
58            SimpleQueryStringQueryFlags::Escape => "ESCAPE",
59            SimpleQueryStringQueryFlags::Fuzzy => "FUZZY",
60            SimpleQueryStringQueryFlags::Near => "NEAR",
61            SimpleQueryStringQueryFlags::None => "NONE",
62            SimpleQueryStringQueryFlags::Not => "NOT",
63            SimpleQueryStringQueryFlags::Or => "OR",
64            SimpleQueryStringQueryFlags::Phrase => "PHRASE",
65            SimpleQueryStringQueryFlags::Precedence => "PRECEDENCE",
66            SimpleQueryStringQueryFlags::Prefix => "PREFIX",
67            SimpleQueryStringQueryFlags::Slop => "SLOP",
68            SimpleQueryStringQueryFlags::Whitespace => "WHITESPACE",
69        }
70    }
71}
72
73impl From<SimpleQueryStringQueryFlags> for String {
74    fn from(value: SimpleQueryStringQueryFlags) -> Self {
75        <&'static str>::from(value).to_string()
76    }
77}
78
79impl std::fmt::Display for SimpleQueryStringQueryFlags {
80    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
81        <&'static str>::from(*self).fmt(f)
82    }
83}
84
85impl Serialize for SimpleQueryStringQueryFlags {
86    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
87    where
88        S: Serializer,
89    {
90        <&'static str>::from(*self).serialize(serializer)
91    }
92}