179: Enable filter paramater during search r=MarinPostma a=MarinPostma

This pr makes the necessary changes to transplant in accordance with the specification on filters.

More precisely, it:
- Removes the `filters` parameter
- Renames `facetFilters` to `filter`
- Allows either a string or an array to be passed to the filter param.

It doesn't allow the mixed syntax, that needs to be handled by milli.

close #81
close #140


Co-authored-by: Marin Postma <postma.marin@protonmail.com>
This commit is contained in:
bors[bot] 2021-06-14 08:11:30 +00:00 committed by GitHub
commit d765397c82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 41 deletions

View file

@ -2,6 +2,7 @@ use std::collections::HashSet;
use std::convert::{TryFrom, TryInto};
use actix_web::{get, post, web, HttpResponse};
use serde_json::Value;
use serde::Deserialize;
use crate::error::ResponseError;
@ -24,9 +25,8 @@ pub struct SearchQueryGet {
attributes_to_crop: Option<String>,
crop_length: Option<usize>,
attributes_to_highlight: Option<String>,
filters: Option<String>,
filter: Option<String>,
matches: Option<bool>,
facet_filters: Option<String>,
facet_distributions: Option<String>,
}
@ -50,8 +50,13 @@ impl TryFrom<SearchQueryGet> for SearchQuery {
.facet_distributions
.map(|attrs| attrs.split(',').map(String::from).collect::<Vec<_>>());
let facet_filters = match other.facet_filters {
Some(ref f) => Some(serde_json::from_str(f)?),
let filter = match other.filter {
Some(f) => {
match serde_json::from_str(&f) {
Ok(v) => Some(v),
_ => Some(Value::String(f)),
}
},
None => None,
};
@ -63,9 +68,8 @@ impl TryFrom<SearchQueryGet> for SearchQuery {
attributes_to_crop,
crop_length: other.crop_length,
attributes_to_highlight,
filters: other.filters,
filter,
matches: other.matches,
facet_filters,
facet_distributions,
})
}