mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-24 13:40:31 +01:00
provide a helper to parse the token but to not handle the errors
This commit is contained in:
parent
efb2f8b325
commit
6c9165b6a8
@ -1,5 +1,6 @@
|
|||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::ops::Bound::{self, Excluded, Included};
|
use std::ops::Bound::{self, Excluded, Included};
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use filter_parser::{Condition, FilterCondition, FilterParserError, Span, Token};
|
use filter_parser::{Condition, FilterCondition, FilterParserError, Span, Token};
|
||||||
@ -27,6 +28,10 @@ impl<'a> From<VerboseError<Span<'a>>> for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse<T: FromStr>(tok: &Token) -> Result<T> {
|
||||||
|
Ok(tok.inner.parse().ok().unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> Filter<'a> {
|
impl<'a> Filter<'a> {
|
||||||
pub fn from_array<I, J>(array: I) -> Result<Option<Self>>
|
pub fn from_array<I, J>(array: I) -> Result<Option<Self>>
|
||||||
where
|
where
|
||||||
@ -206,19 +211,11 @@ impl<'a> Filter<'a> {
|
|||||||
// field id and the level.
|
// field id and the level.
|
||||||
// TODO TAMO: return good error when we can't parse a span
|
// TODO TAMO: return good error when we can't parse a span
|
||||||
let (left, right) = match operator {
|
let (left, right) = match operator {
|
||||||
Condition::GreaterThan(val) => {
|
Condition::GreaterThan(val) => (Excluded(parse(val)?), Included(f64::MAX)),
|
||||||
(Excluded(val.inner.parse::<f64>().unwrap()), Included(f64::MAX))
|
Condition::GreaterThanOrEqual(val) => (Included(parse(val)?), Included(f64::MAX)),
|
||||||
}
|
Condition::LowerThan(val) => (Included(f64::MIN), Excluded(parse(val)?)),
|
||||||
Condition::GreaterThanOrEqual(val) => {
|
Condition::LowerThanOrEqual(val) => (Included(f64::MIN), Included(parse(val)?)),
|
||||||
(Included(val.inner.parse::<f64>().unwrap()), Included(f64::MAX))
|
Condition::Between { from, to } => (Included(parse(from)?), Included(parse(to)?)),
|
||||||
}
|
|
||||||
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::<f64>().unwrap()), Included(to.inner.parse().unwrap()))
|
|
||||||
}
|
|
||||||
Condition::Equal(val) => {
|
Condition::Equal(val) => {
|
||||||
let (_original_value, string_docids) =
|
let (_original_value, string_docids) =
|
||||||
strings_db.get(rtxn, &(field_id, val.inner))?.unwrap_or_default();
|
strings_db.get(rtxn, &(field_id, val.inner))?.unwrap_or_default();
|
||||||
@ -334,6 +331,7 @@ impl<'a> Filter<'a> {
|
|||||||
Ok(lhs & rhs)
|
Ok(lhs & rhs)
|
||||||
}
|
}
|
||||||
FilterCondition::Empty => Ok(RoaringBitmap::new()),
|
FilterCondition::Empty => Ok(RoaringBitmap::new()),
|
||||||
|
// TODO: TAMO
|
||||||
_ => panic!("do the geosearch"),
|
_ => panic!("do the geosearch"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user