mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 06:44:27 +01:00
Improve the returned errors from the facet-search route
This commit is contained in:
parent
a05074e675
commit
702041b7e1
@ -242,11 +242,14 @@ InvalidSearchMatchingStrategy , InvalidRequest , BAD_REQUEST ;
|
|||||||
InvalidSearchOffset , InvalidRequest , BAD_REQUEST ;
|
InvalidSearchOffset , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidSearchPage , InvalidRequest , BAD_REQUEST ;
|
InvalidSearchPage , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidSearchQ , InvalidRequest , BAD_REQUEST ;
|
InvalidSearchQ , InvalidRequest , BAD_REQUEST ;
|
||||||
|
InvalidFacetSearchQuery , InvalidRequest , BAD_REQUEST ;
|
||||||
|
InvalidFacetSearchName , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidSearchVector , InvalidRequest , BAD_REQUEST ;
|
InvalidSearchVector , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidSearchShowMatchesPosition , InvalidRequest , BAD_REQUEST ;
|
InvalidSearchShowMatchesPosition , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidSearchShowRankingScore , InvalidRequest , BAD_REQUEST ;
|
InvalidSearchShowRankingScore , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidSearchShowRankingScoreDetails , InvalidRequest , BAD_REQUEST ;
|
InvalidSearchShowRankingScoreDetails , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidSearchSort , InvalidRequest , BAD_REQUEST ;
|
InvalidSearchSort , InvalidRequest , BAD_REQUEST ;
|
||||||
|
InvalidSearchFacet , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidSettingsDisplayedAttributes , InvalidRequest , BAD_REQUEST ;
|
InvalidSettingsDisplayedAttributes , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidSettingsDistinctAttribute , InvalidRequest , BAD_REQUEST ;
|
InvalidSettingsDistinctAttribute , InvalidRequest , BAD_REQUEST ;
|
||||||
InvalidSettingsFaceting , InvalidRequest , BAD_REQUEST ;
|
InvalidSettingsFaceting , InvalidRequest , BAD_REQUEST ;
|
||||||
@ -340,6 +343,7 @@ impl ErrorCode for milli::Error {
|
|||||||
UserError::InvalidSearchableAttribute { .. } => {
|
UserError::InvalidSearchableAttribute { .. } => {
|
||||||
Code::InvalidAttributesToSearchOn
|
Code::InvalidAttributesToSearchOn
|
||||||
}
|
}
|
||||||
|
UserError::InvalidSearchFacet { .. } => Code::InvalidSearchFacet,
|
||||||
UserError::CriterionError(_) => Code::InvalidSettingsRankingRules,
|
UserError::CriterionError(_) => Code::InvalidSettingsRankingRules,
|
||||||
UserError::InvalidGeoField { .. } => Code::InvalidDocumentGeoField,
|
UserError::InvalidGeoField { .. } => Code::InvalidDocumentGeoField,
|
||||||
UserError::InvalidVectorDimensions { .. } => Code::InvalidVectorDimensions,
|
UserError::InvalidVectorDimensions { .. } => Code::InvalidVectorDimensions,
|
||||||
|
@ -28,9 +28,9 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
|
|||||||
#[derive(Debug, Clone, Default, PartialEq, Eq, deserr::Deserr)]
|
#[derive(Debug, Clone, Default, PartialEq, Eq, deserr::Deserr)]
|
||||||
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)]
|
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)]
|
||||||
pub struct FacetSearchQuery {
|
pub struct FacetSearchQuery {
|
||||||
#[deserr(default, error = DeserrJsonError<InvalidSearchQ>)]
|
#[deserr(default, error = DeserrJsonError<InvalidFacetSearchQuery>)]
|
||||||
pub facet_query: Option<String>,
|
pub facet_query: Option<String>,
|
||||||
#[deserr(default, error = DeserrJsonError<InvalidSearchQ>)]
|
#[deserr(error = DeserrJsonError<InvalidFacetSearchName>)]
|
||||||
pub facet_name: String,
|
pub facet_name: String,
|
||||||
#[deserr(default, error = DeserrJsonError<InvalidSearchQ>)]
|
#[deserr(default, error = DeserrJsonError<InvalidSearchQ>)]
|
||||||
pub q: Option<String>,
|
pub q: Option<String>,
|
||||||
|
@ -128,6 +128,16 @@ only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and undersco
|
|||||||
}
|
}
|
||||||
)]
|
)]
|
||||||
InvalidSortableAttribute { field: String, valid_fields: BTreeSet<String> },
|
InvalidSortableAttribute { field: String, valid_fields: BTreeSet<String> },
|
||||||
|
#[error("Attribute `{}` is not filterable. {}",
|
||||||
|
.field,
|
||||||
|
match .valid_fields.is_empty() {
|
||||||
|
true => "This index does not have configured filterable attributes.".to_string(),
|
||||||
|
false => format!("Available filterable attributes are: `{}`.",
|
||||||
|
valid_fields.iter().map(AsRef::as_ref).collect::<Vec<&str>>().join(", ")
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)]
|
||||||
|
InvalidSearchFacet { field: String, valid_fields: BTreeSet<String> },
|
||||||
#[error("Attribute `{}` is not searchable. Available searchable attributes are: `{}{}`.",
|
#[error("Attribute `{}` is not searchable. Available searchable attributes are: `{}{}`.",
|
||||||
.field,
|
.field,
|
||||||
.valid_fields.iter().map(AsRef::as_ref).collect::<Vec<&str>>().join(", "),
|
.valid_fields.iter().map(AsRef::as_ref).collect::<Vec<&str>>().join(", "),
|
||||||
|
@ -263,8 +263,7 @@ impl<'a> SearchForFacetValue<'a> {
|
|||||||
|
|
||||||
let filterable_fields = index.filterable_fields(rtxn)?;
|
let filterable_fields = index.filterable_fields(rtxn)?;
|
||||||
if !filterable_fields.contains(&self.facet) {
|
if !filterable_fields.contains(&self.facet) {
|
||||||
// TODO create a new type of error
|
return Err(UserError::InvalidSearchFacet {
|
||||||
return Err(UserError::InvalidSortableAttribute {
|
|
||||||
field: self.facet.clone(),
|
field: self.facet.clone(),
|
||||||
valid_fields: filterable_fields.into_iter().collect(),
|
valid_fields: filterable_fields.into_iter().collect(),
|
||||||
})?;
|
})?;
|
||||||
|
Loading…
Reference in New Issue
Block a user