mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 04:17:10 +02:00
add error on search with empty facets
This commit is contained in:
parent
18b56c6af8
commit
2ada9c5d72
3 changed files with 7 additions and 4 deletions
|
@ -183,6 +183,7 @@ pub enum FacetError {
|
|||
AttributeNotFound(String),
|
||||
AttributeNotSet { expected: Vec<String>, found: String },
|
||||
InvalidDocumentAttribute(String),
|
||||
NoAttributesForFaceting,
|
||||
}
|
||||
|
||||
impl FacetError {
|
||||
|
@ -207,6 +208,7 @@ impl fmt::Display for FacetError {
|
|||
AttributeNotFound(attr) => write!(f, "unknown {:?} attribute", attr),
|
||||
AttributeNotSet { found, expected } => write!(f, "`{}` is not set as a faceted attribute. available facet attributes: {}", found, expected.join(", ")),
|
||||
InvalidDocumentAttribute(attr) => write!(f, "invalid document attribute {}, accepted types: String and [String]", attr),
|
||||
NoAttributesForFaceting => write!(f, "impossible to perform faceted search, no attributes for faceting are set"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,9 @@ impl FacetFilter {
|
|||
schema: &Schema,
|
||||
attributes_for_faceting: &[FieldId],
|
||||
) -> MResult<FacetFilter> {
|
||||
if attributes_for_faceting.is_empty() {
|
||||
return Err(FacetError::NoAttributesForFaceting.into());
|
||||
}
|
||||
let parsed = serde_json::from_str::<Value>(s).map_err(|e| FacetError::ParsingError(e.to_string()))?;
|
||||
let mut filter = Vec::new();
|
||||
match parsed {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue