mod span_containing_query;
mod span_field_masking_query;
mod span_first_query;
mod span_multi_query;
mod span_near_query;
mod span_not_query;
mod span_or_query;
mod span_term_query;
mod span_within_query;
pub use self::{
span_containing_query::*, span_field_masking_query::*, span_first_query::*,
span_multi_query::*, span_near_query::*, span_not_query::*, span_or_query::*,
span_term_query::*, span_within_query::*,
};
use crate::{util::*, FuzzyQuery, PrefixQuery, RangeQuery, RegexpQuery, WildcardQuery};
macro_rules! span_query {
($($variant:ident($query:ty)),+ $(,)?) => {
#[derive(Clone, PartialEq, Deserialize, Serialize)]
#[serde(untagged)]
#[allow(missing_docs)]
pub enum SpanQuery {
$(
$variant($query),
)*
}
impl IntoIterator for SpanQuery {
type Item = Self;
type IntoIter = std::option::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
if self.should_skip() {
None.into_iter()
} else {
Some(self).into_iter()
}
}
}
impl ShouldSkip for SpanQuery {
fn should_skip(&self) -> bool {
match self {
$(
Self::$variant(q) => q.should_skip(),
)+
}
}
}
impl std::fmt::Debug for SpanQuery {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
$(
Self::$variant(q) => q.fmt(f),
)+
}
}
}
$(
impl From<$query> for SpanQuery {
fn from(q: $query) -> Self {
SpanQuery::$variant(q)
}
}
impl PartialEq<$query> for SpanQuery {
fn eq(&self, other: &$query) -> bool {
match self {
Self::$variant(query) => query.eq(other),
_ => false,
}
}
}
impl PartialEq<SpanQuery> for $query {
fn eq(&self, other: &SpanQuery) -> bool {
match other {
SpanQuery::$variant(query) => self.eq(query),
_ => false,
}
}
}
impl From<$query> for Option<SpanQuery> {
fn from(q: $query) -> Self {
if q.should_skip() {
None
} else {
Some(SpanQuery::$variant(q))
}
}
}
)+
};
}
macro_rules! multi_term_query {
($($variant:ident($query:ty)),+ $(,)?) => {
#[derive(Clone, PartialEq, Deserialize, Serialize)]
#[serde(untagged)]
#[allow(missing_docs)]
pub enum MultiTermQuery {
$(
$variant($query),
)*
}
impl IntoIterator for MultiTermQuery {
type Item = Self;
type IntoIter = std::option::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
if self.should_skip() {
None.into_iter()
} else {
Some(self).into_iter()
}
}
}
impl ShouldSkip for MultiTermQuery {
fn should_skip(&self) -> bool {
match self {
$(
Self::$variant(q) => q.should_skip(),
)+
}
}
}
impl std::fmt::Debug for MultiTermQuery {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
$(
Self::$variant(q) => q.fmt(f),
)+
}
}
}
$(
impl From<$query> for MultiTermQuery {
fn from(q: $query) -> Self {
MultiTermQuery::$variant(q)
}
}
impl PartialEq<$query> for MultiTermQuery {
fn eq(&self, other: &$query) -> bool {
match self {
Self::$variant(query) => query.eq(other),
_ => false,
}
}
}
impl PartialEq<MultiTermQuery> for $query {
fn eq(&self, other: &MultiTermQuery) -> bool {
match other {
MultiTermQuery::$variant(query) => self.eq(query),
_ => false,
}
}
}
impl From<$query> for Option<MultiTermQuery> {
fn from(q: $query) -> Self {
if q.should_skip() {
None
} else {
Some(MultiTermQuery::$variant(q))
}
}
}
)+
};
}
span_query!(
SpanContaining(SpanContainingQuery),
SpanFieldMasking(SpanFieldMaskingQuery),
SpanFirst(SpanFirstQuery),
SpanMulti(SpanMultiQuery),
SpanNear(SpanNearQuery),
SpanNot(SpanNotQuery),
SpanOr(SpanOrQuery),
SpanTerm(SpanTermQuery),
SpanWithin(SpanWithinQuery),
);
multi_term_query!(
Prefix(PrefixQuery),
Regexp(RegexpQuery),
Wildcard(WildcardQuery),
Range(RangeQuery),
Fuzzy(FuzzyQuery),
);