From 6c9165b6a8161544c76c1a3d63867a72e5983115 Mon Sep 17 00:00:00 2001 From: Tamo Date: Fri, 22 Oct 2021 16:52:13 +0200 Subject: [PATCH] provide a helper to parse the token but to not handle the errors --- milli/src/search/facet/filter_condition.rs | 24 ++++++++++------------ 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/milli/src/search/facet/filter_condition.rs b/milli/src/search/facet/filter_condition.rs index fca35ff4d..2ba5a023e 100644 --- a/milli/src/search/facet/filter_condition.rs +++ b/milli/src/search/facet/filter_condition.rs @@ -1,5 +1,6 @@ use std::fmt::Debug; use std::ops::Bound::{self, Excluded, Included}; +use std::str::FromStr; use either::Either; use filter_parser::{Condition, FilterCondition, FilterParserError, Span, Token}; @@ -27,6 +28,10 @@ impl<'a> From>> for Error { } } +fn parse(tok: &Token) -> Result { + Ok(tok.inner.parse().ok().unwrap()) +} + impl<'a> Filter<'a> { pub fn from_array(array: I) -> Result> where @@ -206,19 +211,11 @@ impl<'a> Filter<'a> { // field id and the level. // TODO TAMO: return good error when we can't parse a span let (left, right) = match operator { - Condition::GreaterThan(val) => { - (Excluded(val.inner.parse::().unwrap()), Included(f64::MAX)) - } - Condition::GreaterThanOrEqual(val) => { - (Included(val.inner.parse::().unwrap()), Included(f64::MAX)) - } - Condition::LowerThan(val) => (Included(f64::MIN), Excluded(val.inner.parse().unwrap())), - Condition::LowerThanOrEqual(val) => { - (Included(f64::MIN), Included(val.inner.parse().unwrap())) - } - Condition::Between { from, to } => { - (Included(from.inner.parse::().unwrap()), Included(to.inner.parse().unwrap())) - } + Condition::GreaterThan(val) => (Excluded(parse(val)?), Included(f64::MAX)), + Condition::GreaterThanOrEqual(val) => (Included(parse(val)?), Included(f64::MAX)), + Condition::LowerThan(val) => (Included(f64::MIN), Excluded(parse(val)?)), + Condition::LowerThanOrEqual(val) => (Included(f64::MIN), Included(parse(val)?)), + Condition::Between { from, to } => (Included(parse(from)?), Included(parse(to)?)), Condition::Equal(val) => { let (_original_value, string_docids) = strings_db.get(rtxn, &(field_id, val.inner))?.unwrap_or_default(); @@ -334,6 +331,7 @@ impl<'a> Filter<'a> { Ok(lhs & rhs) } FilterCondition::Empty => Ok(RoaringBitmap::new()), + // TODO: TAMO _ => panic!("do the geosearch"), } }