os_query_builder_rs/full_text/
query_string.rs1use serde::Serialize;
2use crate::misc::fuzziness::Fuzziness;
3use crate::misc::operator::Operator;
4use crate::misc::r#type::Type;
5
6#[derive(Debug, Default, Clone, Serialize)]
7pub struct QueryString {
8 query: Option<String>,
9
10 #[serde(skip_serializing_if = "Option::is_none")]
11 default_field: Option<String>,
12
13 #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
14 query_type: Option<Type>,
15
16 #[serde(skip_serializing_if = "Option::is_none")]
17 fuzziness: Option<Fuzziness>,
18
19 #[serde(skip_serializing_if = "Option::is_none")]
20 fuzzy_transpositions: Option<bool>,
21
22 #[serde(skip_serializing_if = "Option::is_none")]
23 fuzzy_max_expansions: Option<u64>,
24
25 #[serde(skip_serializing_if = "Option::is_none")]
26 fuzzy_prefix_length: Option<u64>,
27
28 #[serde(skip_serializing_if = "Option::is_none")]
29 minimum_should_match: Option<String>,
30
31 #[serde(skip_serializing_if = "Option::is_none")]
32 default_operator: Option<Operator>,
33
34 #[serde(skip_serializing_if = "Option::is_none")]
35 analyzer: Option<String>,
36
37 #[serde(skip_serializing_if = "Option::is_none")]
38 lenient: Option<bool>,
39
40 #[serde(skip_serializing_if = "Option::is_none")]
41 boost: Option<f64>,
42
43 #[serde(skip_serializing_if = "Option::is_none")]
44 allow_leading_wildcard: Option<bool>,
45
46 #[serde(skip_serializing_if = "Option::is_none")]
47 enable_position_increments: Option<bool>,
48
49 #[serde(skip_serializing_if = "Option::is_none")]
50 phrase_slop: Option<u64>,
51
52 #[serde(skip_serializing_if = "Option::is_none")]
53 max_determinized_states: Option<u64>,
54
55 #[serde(skip_serializing_if = "Option::is_none")]
56 time_zone: Option<String>,
57
58 #[serde(skip_serializing_if = "Option::is_none")]
59 quote_field_suffix: Option<String>,
60
61 #[serde(skip_serializing_if = "Option::is_none")]
62 quote_analyzer: Option<String>,
63
64 #[serde(skip_serializing_if = "Option::is_none")]
65 analyze_wildcard: Option<bool>,
66
67 #[serde(skip_serializing_if = "Option::is_none")]
68 auto_generate_synonyms_phrase_query: Option<bool>,
69}
70
71impl QueryString {
72 pub fn new() -> Self {
73 Self::default()
74 }
75
76 pub fn value<T: Into<String>>(self, value: T) -> Self {
77 Self {
78 query: Some(value.into()),
79 ..self
80 }
81 }
82
83 pub fn query<T: Into<String>>(self, query: T) -> Self {
84 self.value(query)
85 }
86
87 pub fn default_field<T: Into<String>>(self, default_field: T) -> Self {
88 Self {
89 default_field: Some(default_field.into()),
90 ..self
91 }
92 }
93
94 pub fn query_type<T: Into<Type>>(self, typ: T) -> Self {
95 Self {
96 query_type: Some(typ.into()),
97 ..self
98 }
99 }
100
101 pub fn fuzziness<T: Into<Fuzziness>>(self, fuzziness: T) -> Self {
102 Self {
103 fuzziness: Some(fuzziness.into()),
104 ..self
105 }
106 }
107
108 pub fn fuzzy_transpositions(self, fuzzy_transpositions: bool) -> Self {
109 Self {
110 fuzzy_transpositions: Some(fuzzy_transpositions),
111 ..self
112 }
113 }
114
115 pub fn fuzzy_max_expansions<T: Into<u64>>(self, fuzzy_max_expansions: T) -> Self {
116 Self {
117 fuzzy_max_expansions: Some(fuzzy_max_expansions.into()),
118 ..self
119 }
120 }
121
122 pub fn fuzzy_prefix_length<T: Into<u64>>(self, fuzzy_prefix_length: T) -> Self {
123 Self {
124 fuzzy_prefix_length: Some(fuzzy_prefix_length.into()),
125 ..self
126 }
127 }
128
129 pub fn minimum_should_match<T: Into<String>>(self, minimum_should_match: T) -> Self {
130 Self {
131 minimum_should_match: Some(minimum_should_match.into()),
132 ..self
133 }
134 }
135
136 pub fn default_operator<T: Into<Operator>>(self, default_operator: T) -> Self {
137 Self {
138 default_operator: Some(default_operator.into()),
139 ..self
140 }
141 }
142
143 pub fn analyzer<T: Into<String>>(self, analyzer: T) -> Self {
144 Self {
145 analyzer: Some(analyzer.into()),
146 ..self
147 }
148 }
149
150 pub fn lenient(self, lenient: bool) -> Self {
151 Self {
152 lenient: Some(lenient),
153 ..self
154 }
155 }
156
157 pub fn boost<T: Into<f64>>(self, boost: T) -> Self {
158 Self {
159 boost: Some(boost.into()),
160 ..self
161 }
162 }
163
164 pub fn allow_leading_wildcard(self, allow_leading_wildcard: bool) -> Self {
165 Self {
166 allow_leading_wildcard: Some(allow_leading_wildcard),
167 ..self
168 }
169 }
170
171 pub fn enable_position_increments(self, enable_position_increments: bool) -> Self {
172 Self {
173 enable_position_increments: Some(enable_position_increments),
174 ..self
175 }
176 }
177
178 pub fn phrase_slop<T: Into<u64>>(self, phrase_slop: T) -> Self {
179 Self {
180 phrase_slop: Some(phrase_slop.into()),
181 ..self
182 }
183 }
184
185 pub fn max_determinized_states<T: Into<u64>>(self, max_determinized_states: T) -> Self {
186 Self {
187 max_determinized_states: Some(max_determinized_states.into()),
188 ..self
189 }
190 }
191
192 pub fn time_zone<T: Into<String>>(self, time_zone: T) -> Self {
193 Self {
194 time_zone: Some(time_zone.into()),
195 ..self
196 }
197 }
198
199 pub fn quote_field_suffix<T: Into<String>>(self, quote_field_suffix: T) -> Self {
200 Self {
201 quote_field_suffix: Some(quote_field_suffix.into()),
202 ..self
203 }
204 }
205
206 pub fn quote_analyzer<T: Into<String>>(self, quote_analyzer: T) -> Self {
207 Self {
208 quote_analyzer: Some(quote_analyzer.into()),
209 ..self
210 }
211 }
212
213 pub fn analyze_wildcard(self, analyze_wildcard: bool) -> Self {
214 Self {
215 analyze_wildcard: Some(analyze_wildcard),
216 ..self
217 }
218 }
219
220 pub fn auto_generate_synonyms_phrase_query(
221 self,
222 auto_generate_synonyms_phrase_query: bool,
223 ) -> Self {
224 Self {
225 auto_generate_synonyms_phrase_query: Some(auto_generate_synonyms_phrase_query),
226 ..self
227 }
228 }
229}