update http-ui

This commit is contained in:
Tamo 2021-11-04 15:52:22 +01:00
parent a58bc5bebb
commit 07a5ffb04c
No known key found for this signature in database
GPG Key ID: 20CD8020AFA88D69
2 changed files with 21 additions and 9 deletions

View File

@ -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::<Vec<&str>>())
}
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 {

View File

@ -35,6 +35,12 @@ fn parse<T: FromStr>(tok: &Token) -> Result<T> {
}
}
impl<'a> From<Filter<'a>> for FilterCondition<'a> {
fn from(f: Filter<'a>) -> Self {
f.condition
}
}
impl<'a> Filter<'a> {
pub fn from_array<I, J>(array: I) -> Result<Option<Self>>
where