elastic_query_builder/query/
match_all_query.rs

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