1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use crate::query::QueryTrait;
use serde_json::{json, Value};
use crate::util::UtilMap;
#[derive(Default)]
pub struct WildcardQuery {
field: String,
value: String,
boost: Option<f64>,
}
impl WildcardQuery {
pub fn new(field: &str, value: &str) -> WildcardQuery {
let mut query = WildcardQuery::default();
query.field = field.to_string();
query.value = value.to_string();
return query;
}
pub fn set_boost(mut self, boost: f64) -> WildcardQuery {
self.boost = Some(boost);
self
}
}
impl QueryTrait for WildcardQuery {
fn build(&self) -> Value {
let mut query = UtilMap::new();
query.append_string("value",self.value.to_string());
query.append_boost(self.boost);
let mut root = UtilMap::new();
root.append_object(self.field.to_string(),query);
root.build_object(self.query_name())
}
fn query_name(&self) -> String {
return "wildcard".to_string();
}
}
#[test]
fn test() {
let build = WildcardQuery::new("title", "elastic").set_boost(100.0);
assert_eq!("{\"wildcard\":{\"title\":{\"boost\":100.0,\"value\":\"elastic\"}}}", build.build().to_string());
}