mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 13:24:27 +01:00
Introduce a new InvalidFacetsDistribution user error
This commit is contained in:
parent
2364777838
commit
a6218a20ae
@ -1,3 +1,4 @@
|
|||||||
|
use std::collections::HashSet;
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::error::Error as StdError;
|
use std::error::Error as StdError;
|
||||||
use std::{fmt, io, str};
|
use std::{fmt, io, str};
|
||||||
@ -51,13 +52,14 @@ pub enum FieldIdMapMissingEntry {
|
|||||||
pub enum UserError {
|
pub enum UserError {
|
||||||
AttributeLimitReached,
|
AttributeLimitReached,
|
||||||
Csv(csv::Error),
|
Csv(csv::Error),
|
||||||
MaxDatabaseSizeReached,
|
|
||||||
DocumentLimitReached,
|
DocumentLimitReached,
|
||||||
InvalidFilter(pest::error::Error<ParserRule>),
|
|
||||||
InvalidCriterionName { name: String },
|
InvalidCriterionName { name: String },
|
||||||
InvalidDocumentId { document_id: Value },
|
InvalidDocumentId { document_id: Value },
|
||||||
|
InvalidFacetsDistribution { invalid_facets_name: HashSet<String> },
|
||||||
|
InvalidFilter(pest::error::Error<ParserRule>),
|
||||||
InvalidFilterAttribute(pest::error::Error<ParserRule>),
|
InvalidFilterAttribute(pest::error::Error<ParserRule>),
|
||||||
InvalidStoreFile,
|
InvalidStoreFile,
|
||||||
|
MaxDatabaseSizeReached,
|
||||||
MissingDocumentId { document: Object },
|
MissingDocumentId { document: Object },
|
||||||
MissingPrimaryKey,
|
MissingPrimaryKey,
|
||||||
NoSpaceLeftOnDevice,
|
NoSpaceLeftOnDevice,
|
||||||
@ -202,6 +204,15 @@ impl fmt::Display for UserError {
|
|||||||
Self::AttributeLimitReached => f.write_str("maximum number of attributes reached"),
|
Self::AttributeLimitReached => f.write_str("maximum number of attributes reached"),
|
||||||
Self::Csv(error) => error.fmt(f),
|
Self::Csv(error) => error.fmt(f),
|
||||||
Self::DocumentLimitReached => f.write_str("maximum number of documents reached"),
|
Self::DocumentLimitReached => f.write_str("maximum number of documents reached"),
|
||||||
|
Self::InvalidFacetsDistribution { invalid_facets_name } => {
|
||||||
|
let name_list =
|
||||||
|
invalid_facets_name.iter().map(AsRef::as_ref).collect::<Vec<_>>().join(", ");
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"invalid facet distribution, the fields {} are not set as filterable",
|
||||||
|
name_list
|
||||||
|
)
|
||||||
|
}
|
||||||
Self::InvalidFilter(error) => error.fmt(f),
|
Self::InvalidFilter(error) => error.fmt(f),
|
||||||
Self::InvalidCriterionName { name } => write!(f, "invalid criterion {}", name),
|
Self::InvalidCriterionName { name } => write!(f, "invalid criterion {}", name),
|
||||||
Self::InvalidDocumentId { document_id } => {
|
Self::InvalidDocumentId { document_id } => {
|
||||||
|
@ -6,7 +6,7 @@ use heed::types::{ByteSlice, Unit};
|
|||||||
use heed::{BytesDecode, Database};
|
use heed::{BytesDecode, Database};
|
||||||
use roaring::RoaringBitmap;
|
use roaring::RoaringBitmap;
|
||||||
|
|
||||||
use crate::error::FieldIdMapMissingEntry;
|
use crate::error::{FieldIdMapMissingEntry, UserError};
|
||||||
use crate::facet::FacetType;
|
use crate::facet::FacetType;
|
||||||
use crate::heed_codec::facet::FacetValueStringCodec;
|
use crate::heed_codec::facet::FacetValueStringCodec;
|
||||||
use crate::search::facet::{FacetIter, FacetRange};
|
use crate::search::facet::{FacetIter, FacetRange};
|
||||||
@ -219,7 +219,10 @@ impl<'a> FacetDistribution<'a> {
|
|||||||
Some(ref facets) => {
|
Some(ref facets) => {
|
||||||
let invalid_fields: HashSet<_> = facets.difference(&filterable_fields).collect();
|
let invalid_fields: HashSet<_> = facets.difference(&filterable_fields).collect();
|
||||||
if !invalid_fields.is_empty() {
|
if !invalid_fields.is_empty() {
|
||||||
todo!("return an error specifying that these fields are not filterable");
|
return Err(UserError::InvalidFacetsDistribution {
|
||||||
|
invalid_facets_name: invalid_fields.into_iter().cloned().collect(),
|
||||||
|
}
|
||||||
|
.into());
|
||||||
} else {
|
} else {
|
||||||
facets.clone()
|
facets.clone()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user