mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-27 07:00:05 +01:00
Introduce the depth method on FilterCondition
This commit is contained in:
parent
c83b77304a
commit
57502fcf6a
@ -113,6 +113,17 @@ pub enum FilterCondition<'a> {
|
||||
}
|
||||
|
||||
impl<'a> FilterCondition<'a> {
|
||||
pub fn depth(&self) -> usize {
|
||||
match self {
|
||||
FilterCondition::Condition { .. } => 1,
|
||||
FilterCondition::Or(left, right) => 1 + left.depth().max(right.depth()),
|
||||
FilterCondition::And(left, right) => 1 + left.depth().max(right.depth()),
|
||||
FilterCondition::GeoLowerThan { .. } => 1,
|
||||
FilterCondition::GeoGreaterThan { .. } => 1,
|
||||
FilterCondition::Empty => 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn negate(self) -> FilterCondition<'a> {
|
||||
use FilterCondition::*;
|
||||
|
||||
@ -584,4 +595,10 @@ pub mod tests {
|
||||
assert!(filter.starts_with(expected), "Filter `{:?}` was supposed to return the following error:\n{}\n, but instead returned\n{}\n.", input, expected, filter);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn depth() {
|
||||
let filter = FilterCondition::parse("account_ids=1 OR account_ids=2 OR account_ids=3 OR account_ids=4 OR account_ids=5 OR account_ids=6").unwrap();
|
||||
assert_eq!(filter.depth(), 6);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user