os_query_builder_rs/full_text/
simple_query_string.rs1use serde::Serialize;
2use crate::misc::operator::Operator;
3
4#[derive(Debug, Default, Clone, Serialize)]
5pub struct SimpleQueryString {
6 query: Option<String>,
7 fields: Vec<String>,
8
9 #[serde(skip_serializing_if = "Option::is_none")]
10 flags: Option<String>,
11
12 #[serde(skip_serializing_if = "Option::is_none")]
13 fuzzy_transpositions: Option<bool>,
14
15 #[serde(skip_serializing_if = "Option::is_none")]
16 fuzzy_max_expansions: Option<u64>,
17
18 #[serde(skip_serializing_if = "Option::is_none")]
19 fuzzy_prefix_length: Option<u64>,
20
21 #[serde(skip_serializing_if = "Option::is_none")]
22 minimum_should_match: Option<String>,
23
24 #[serde(skip_serializing_if = "Option::is_none")]
25 default_operator: Option<Operator>,
26
27 #[serde(skip_serializing_if = "Option::is_none")]
28 analyzer: Option<String>,
29
30 #[serde(skip_serializing_if = "Option::is_none")]
31 lenient: Option<bool>,
32
33 #[serde(skip_serializing_if = "Option::is_none")]
34 quote_field_suffix: Option<String>,
35
36 #[serde(skip_serializing_if = "Option::is_none")]
37 analyze_wildcard: Option<bool>,
38
39 #[serde(skip_serializing_if = "Option::is_none")]
40 auto_generate_synonyms_phrase_query: Option<bool>,
41}
42
43impl SimpleQueryString {
44 pub fn new() -> Self {
45 Self::default()
46 }
47
48 pub fn fields<F, T>(self, fields: F) -> Self
49 where
50 F: IntoIterator<Item = T>,
51 T: Into<String>,
52 {
53 Self {
54 fields: fields.into_iter().map(|f| f.into()).collect(),
55 ..self
56 }
57 }
58
59 pub fn field<T: Into<String>>(self, field: T) -> Self {
60 let mut fields = self.fields;
61 fields.push(field.into());
62 Self { fields, ..self }
63 }
64
65 pub fn value<T: Into<String>>(self, value: T) -> Self {
66 Self {
67 query: Some(value.into()),
68 ..self
69 }
70 }
71
72 pub fn query<T: Into<String>>(self, query: T) -> Self {
73 self.value(query)
74 }
75
76 pub fn flags<T: Into<String>>(self, flags: T) -> Self {
77 Self {
78 flags: Some(flags.into()),
79 ..self
80 }
81 }
82
83 pub fn fuzzy_transpositions(self, fuzzy_transpositions: bool) -> Self {
84 Self {
85 fuzzy_transpositions: Some(fuzzy_transpositions),
86 ..self
87 }
88 }
89
90 pub fn fuzzy_max_expansions<T: Into<u64>>(self, fuzzy_max_expansions: T) -> Self {
91 Self {
92 fuzzy_max_expansions: Some(fuzzy_max_expansions.into()),
93 ..self
94 }
95 }
96
97 pub fn fuzzy_prefix_length<T: Into<u64>>(self, fuzzy_prefix_length: T) -> Self {
98 Self {
99 fuzzy_prefix_length: Some(fuzzy_prefix_length.into()),
100 ..self
101 }
102 }
103
104 pub fn minimum_should_match<T: Into<String>>(self, minimum_should_match: T) -> Self {
105 Self {
106 minimum_should_match: Some(minimum_should_match.into()),
107 ..self
108 }
109 }
110
111 pub fn default_operator<T: Into<Operator>>(self, default_operator: T) -> Self {
112 Self {
113 default_operator: Some(default_operator.into()),
114 ..self
115 }
116 }
117
118 pub fn analyzer<T: Into<String>>(self, analyzer: T) -> Self {
119 Self {
120 analyzer: Some(analyzer.into()),
121 ..self
122 }
123 }
124
125 pub fn lenient(self, lenient: bool) -> Self {
126 Self {
127 lenient: Some(lenient),
128 ..self
129 }
130 }
131
132 pub fn quote_field_suffix<T: Into<String>>(self, quote_field_suffix: T) -> Self {
133 Self {
134 quote_field_suffix: Some(quote_field_suffix.into()),
135 ..self
136 }
137 }
138
139 pub fn analyze_wildcard(self, analyze_wildcard: bool) -> Self {
140 Self {
141 analyze_wildcard: Some(analyze_wildcard),
142 ..self
143 }
144 }
145
146 pub fn auto_generate_synonyms_phrase_query(
147 self,
148 auto_generate_synonyms_phrase_query: bool,
149 ) -> Self {
150 Self {
151 auto_generate_synonyms_phrase_query: Some(auto_generate_synonyms_phrase_query),
152 ..self
153 }
154 }
155}