From 07a5ffb04c3e3e241d7bf4b9f0e1d6c5bf5ddeb4 Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 4 Nov 2021 15:52:22 +0100 Subject: [PATCH] update http-ui --- http-ui/src/main.rs | 24 ++++++++++++++-------- milli/src/search/facet/filter_condition.rs | 6 ++++++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/http-ui/src/main.rs b/http-ui/src/main.rs index e3f8f0317..e84c94e50 100644 --- a/http-ui/src/main.rs +++ b/http-ui/src/main.rs @@ -738,31 +738,37 @@ async fn main() -> anyhow::Result<()> { search.query(query); } - let filters = match query.filters { + let filters = match query.filters.as_ref() { Some(condition) if !condition.trim().is_empty() => { - Some(MilliFilter::from_str(&condition).unwrap()) + Some(MilliFilter::from_str(condition).unwrap()) } _otherwise => None, }; - let facet_filters = match query.facet_filters { + let facet_filters = match query.facet_filters.as_ref() { Some(array) => { - let eithers = array.into_iter().map(Into::into); + let eithers = array.iter().map(|either| match either { + UntaggedEither::Left(l) => { + Either::Left(l.iter().map(|s| s.as_str()).collect::>()) + } + UntaggedEither::Right(r) => Either::Right(r.as_str()), + }); MilliFilter::from_array(eithers).unwrap() } _otherwise => None, }; let condition = match (filters, facet_filters) { - (Some(filters), Some(facet_filters)) => { - Some(FilterCondition::And(Box::new(filters), Box::new(facet_filters))) - } - (Some(condition), None) | (None, Some(condition)) => Some(condition), + (Some(filters), Some(facet_filters)) => Some(FilterCondition::And( + Box::new(filters.into()), + Box::new(facet_filters.into()), + )), + (Some(condition), None) | (None, Some(condition)) => Some(condition.into()), _otherwise => None, }; if let Some(condition) = condition { - search.filter(condition); + search.filter(condition.into()); } if let Some(limit) = query.limit { diff --git a/milli/src/search/facet/filter_condition.rs b/milli/src/search/facet/filter_condition.rs index bb342fa27..d0c32c8f4 100644 --- a/milli/src/search/facet/filter_condition.rs +++ b/milli/src/search/facet/filter_condition.rs @@ -35,6 +35,12 @@ fn parse(tok: &Token) -> Result { } } +impl<'a> From> for FilterCondition<'a> { + fn from(f: Filter<'a>) -> Self { + f.condition + } +} + impl<'a> Filter<'a> { pub fn from_array(array: I) -> Result> where