elasticsearch_dsl/search/queries/full_text/
match_bool_prefix_query.rs1use crate::search::*;
2use crate::util::*;
3
4#[derive(Debug, Clone, PartialEq, Serialize)]
20#[serde(remote = "Self")]
21pub struct MatchBoolPrefixQuery {
22 #[serde(skip)]
23 field: String,
24
25 #[serde(skip_serializing_if = "ShouldSkip::should_skip")]
26 query: Text,
27
28 #[serde(skip_serializing_if = "ShouldSkip::should_skip")]
29 analyzer: Option<String>,
30
31 #[serde(skip_serializing_if = "ShouldSkip::should_skip")]
32 minimum_should_match: Option<String>,
33
34 #[serde(skip_serializing_if = "ShouldSkip::should_skip")]
35 operator: Option<Operator>,
36
37 #[serde(skip_serializing_if = "ShouldSkip::should_skip")]
38 boost: Option<f32>,
39
40 #[serde(skip_serializing_if = "ShouldSkip::should_skip")]
41 _name: Option<String>,
42}
43
44impl Query {
45 pub fn match_bool_prefix<T, U>(field: T, query: U) -> MatchBoolPrefixQuery
50 where
51 T: ToString,
52 U: Into<Text>,
53 {
54 MatchBoolPrefixQuery {
55 field: field.to_string(),
56 query: query.into(),
57 analyzer: None,
58 minimum_should_match: None,
59 operator: None,
60 boost: None,
61 _name: None,
62 }
63 }
64}
65
66impl MatchBoolPrefixQuery {
67 pub fn analyzer<T>(mut self, analyzer: T) -> Self
72 where
73 T: ToString,
74 {
75 self.analyzer = Some(analyzer.to_string());
76 self
77 }
78
79 pub fn minimum_should_match<T>(mut self, minimum_should_match: T) -> Self
82 where
83 T: ToString,
84 {
85 self.minimum_should_match = Some(minimum_should_match.to_string());
86 self
87 }
88
89 pub fn operator(mut self, operator: Operator) -> Self {
91 self.operator = Some(operator);
92 self
93 }
94
95 add_boost_and_name!();
96}
97
98impl ShouldSkip for MatchBoolPrefixQuery {
99 fn should_skip(&self) -> bool {
100 self.query.should_skip()
101 }
102}
103
104serialize_with_root_keyed!("match_bool_prefix": MatchBoolPrefixQuery);
105
106#[cfg(test)]
107mod tests {
108 use super::*;
109
110 #[test]
111 fn serialization() {
112 assert_serialize_query(
113 Query::match_bool_prefix("test", "search text"),
114 json!({
115 "match_bool_prefix": {
116 "test": {
117 "query": "search text"
118 }
119 }
120 }),
121 );
122
123 assert_serialize_query(
124 Query::match_bool_prefix("test", "search text")
125 .analyzer("search_time_analyzer")
126 .minimum_should_match("12")
127 .operator(Operator::Or)
128 .boost(2)
129 .name("test"),
130 json!({
131 "match_bool_prefix": {
132 "test": {
133 "query": "search text",
134 "analyzer": "search_time_analyzer",
135 "minimum_should_match": "12",
136 "operator": "OR",
137 "boost": 2.0,
138 "_name": "test"
139 }
140 }
141 }),
142 );
143 }
144}