os_query_builder_rs/compound_query/
bool.rs1use serde::Serialize;
2use crate::misc::query_field::QueryField;
3
4
5#[derive(Debug, Clone, Serialize)]
6pub struct Bool {
7 #[serde(skip_serializing_if = "Option::is_none")]
8 must: Option<Vec<QueryField>>,
9
10 #[serde(skip_serializing_if = "Option::is_none")]
11 must_not: Option<Vec<QueryField>>,
12
13 #[serde(skip_serializing_if = "Option::is_none")]
14 filter: Option<Vec<QueryField>>,
15
16 #[serde(skip_serializing_if = "Option::is_none")]
17 should: Option<Vec<QueryField>>,
18
19 #[serde(skip_serializing_if = "Option::is_none")]
20 minimum_should_match: Option<usize>
21
22}
23
24impl Bool {
25
26 pub fn new() -> Self {
27 Self {
28 must: None,
29 must_not: None,
30 should: None,
31 filter: None,
32 minimum_should_match: None
33 }
34 }
35
36 pub fn must<T,F>(self, must_value: F) -> Self
37 where T: Into<QueryField>,
38 F: IntoIterator<Item = T>
39 {
40
41 Self {
42 must: Some(must_value.into_iter().map(|x| x.into()).collect()),
43 ..self
44 }
45 }
46
47 pub fn must_not<T,F>(self, must_value: F) -> Self
48 where T: Into<QueryField>,
49 F: IntoIterator<Item = T>
50 {
51
52 Self {
53 must_not: Some(must_value.into_iter().map(|x| x.into()).collect()),
54 ..self
55 }
56 }
57
58 pub fn should<T,F>(self, must_value: F) -> Self
59 where T: Into<QueryField>,
60 F: IntoIterator<Item = T>
61 {
62
63 Self {
64 should: Some(must_value.into_iter().map(|x| x.into()).collect()),
65 ..self
66 }
67 }
68
69 pub fn filter<T,F>(self, filter_values: F) -> Self
70 where T: Into<QueryField>,
71 F: IntoIterator<Item = T>
72 {
73
74 Self {
75 filter: Some(filter_values.into_iter().map(|x| x.into()).collect()),
76 ..self
77 }
78 }
79
80 pub fn minimum_should_match<T: Into<usize>>(self, minimum_should_match : T) -> Self {
81 Self {
82 minimum_should_match: Some(minimum_should_match.into()),
83 ..self
84 }
85 }
86
87}