elasticsearch_dsl/search/queries/span/
span_or_query.rs

1use super::SpanQuery;
2use crate::util::*;
3use crate::Query;
4use serde::Serialize;
5
6/// Matches the union of its span clauses. The span or query maps to Lucene `SpanOrQuery`.
7///
8/// The `clauses` element is a list of one or more other span type queries.
9///
10/// <https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-or-query.html>
11#[derive(Debug, Clone, PartialEq, Serialize)]
12#[serde(remote = "Self")]
13pub struct SpanOrQuery {
14    clauses: Vec<SpanQuery>,
15}
16
17impl ShouldSkip for SpanOrQuery {}
18
19impl Query {
20    /// Creates an instance of [`SpanOrQuery`]
21    pub fn span_or<T>(clauses: T) -> SpanOrQuery
22    where
23        T: IntoIterator,
24        T::Item: Into<SpanQuery>,
25    {
26        SpanOrQuery {
27            clauses: clauses.into_iter().map(Into::into).collect(),
28        }
29    }
30}
31
32serialize_with_root!("span_or": SpanOrQuery);
33
34#[cfg(test)]
35mod tests {
36    use super::*;
37
38    #[test]
39    fn serialization() {
40        assert_serialize_query(
41            Query::span_or([Query::span_term("test", 1234)]),
42            json!({
43                "span_or": {
44                    "clauses": [
45                        {
46                            "span_term": {
47                                "test": {
48                                    "value": 1234
49                                }
50                            }
51                        }
52                    ]
53                }
54            }),
55        );
56
57        assert_serialize_query(
58            Query::span_or([Query::span_term("test", 1234)]),
59            json!({
60                "span_or": {
61                    "clauses": [
62                        {
63                            "span_term": {
64                                "test": {
65                                    "value": 1234
66                                }
67                            }
68                        }
69                    ]
70                }
71            }),
72        );
73    }
74}