From e1d81342cf39894c1c99c5e0e042752d1d909355 Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 21 Oct 2021 13:01:25 +0200 Subject: [PATCH] add test on the or and and operator --- milli/src/search/facet/filter_parser.rs | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/milli/src/search/facet/filter_parser.rs b/milli/src/search/facet/filter_parser.rs index 1ba4962f8..3454d91a4 100644 --- a/milli/src/search/facet/filter_parser.rs +++ b/milli/src/search/facet/filter_parser.rs @@ -469,6 +469,54 @@ mod tests { Fc::from_str(&rtxn, &index, "NOT _geoRadius(12, 13, 14)"), Fc::Operator(3, Operator::GeoGreaterThan([12., 13.], 14.)), ), + // test simple `or` and `and` + ( + Fc::from_str(&rtxn, &index, "channel = ponce AND 'dog race' != 'bernese mountain'"), + Fc::And( + Box::new(Fc::Operator(0, Operator::Equal(None, S("ponce")))), + Box::new(Fc::Operator(1, Operator::NotEqual(None, S("bernese mountain")))), + ), + ), + ( + Fc::from_str(&rtxn, &index, "channel = ponce OR 'dog race' != 'bernese mountain'"), + Fc::Or( + Box::new(Fc::Operator(0, Operator::Equal(None, S("ponce")))), + Box::new(Fc::Operator(1, Operator::NotEqual(None, S("bernese mountain")))), + ), + ), + ( + Fc::from_str( + &rtxn, + &index, + "channel = ponce AND 'dog race' != 'bernese mountain' OR subscribers > 1000", + ), + Fc::Or( + Box::new(Fc::And( + Box::new(Fc::Operator(0, Operator::Equal(None, S("ponce")))), + Box::new(Fc::Operator(1, Operator::NotEqual(None, S("bernese mountain")))), + )), + Box::new(Fc::Operator(2, Operator::GreaterThan(1000.))), + ), + ), + // test parenthesis + /* + ( + Fc::from_str( + &rtxn, + &index, + "(channel = ponce AND 'dog race' != 'bernese mountain' OR subscribers > 1000) AND _geoRadius(12, 13, 14)", + ), + Fc::And( + Box::new(Fc::Or( + Box::new(Fc::And( + Box::new(Fc::Operator(0, Operator::Equal(None, S("ponce")))), + Box::new(Fc::Operator(1, Operator::NotEqual(None, S("bernese mountain")))), + )), + Box::new(Fc::Operator(2, Operator::GreaterThan(1000.))), + )), + Box::new(Fc::Operator(3, Operator::GeoLowerThan([12., 13.], 14.)))) + ), + */ ]; for (result, expected) in test_case {