mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 13:24:27 +01:00
Merge #766
766: Indicate filterable attributes when the user sets a non filterable attribute in facet distributions r=irevoire a=dureuill # Pull Request ## Related issue Related to https://github.com/meilisearch/meilisearch/issues/3390 ## What does this PR do? - Title ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: Louis Dureuil <louis@meilisearch.com>
This commit is contained in:
commit
e7c0617699
@ -1,5 +1,6 @@
|
|||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
|
use std::fmt::Write;
|
||||||
use std::{io, str};
|
use std::{io, str};
|
||||||
|
|
||||||
use heed::{Error as HeedError, MdbError};
|
use heed::{Error as HeedError, MdbError};
|
||||||
@ -100,10 +101,11 @@ A document identifier can be of type integer or string, \
|
|||||||
only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and underscores (_).", .document_id.to_string()
|
only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and underscores (_).", .document_id.to_string()
|
||||||
)]
|
)]
|
||||||
InvalidDocumentId { document_id: Value },
|
InvalidDocumentId { document_id: Value },
|
||||||
#[error("Invalid facet distribution, the fields `{}` are not set as filterable.",
|
#[error("Invalid facet distribution, {}", format_invalid_filter_distribution(.invalid_facets_name, .valid_facets_name))]
|
||||||
.invalid_facets_name.iter().map(AsRef::as_ref).collect::<Vec<&str>>().join(", ")
|
InvalidFacetsDistribution {
|
||||||
)]
|
invalid_facets_name: BTreeSet<String>,
|
||||||
InvalidFacetsDistribution { invalid_facets_name: BTreeSet<String> },
|
valid_facets_name: BTreeSet<String>,
|
||||||
|
},
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
InvalidGeoField(#[from] GeoError),
|
InvalidGeoField(#[from] GeoError),
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
@ -166,6 +168,50 @@ pub enum GeoError {
|
|||||||
BadLongitude { document_id: Value, value: Value },
|
BadLongitude { document_id: Value, value: Value },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn format_invalid_filter_distribution(
|
||||||
|
invalid_facets_name: &BTreeSet<String>,
|
||||||
|
valid_facets_name: &BTreeSet<String>,
|
||||||
|
) -> String {
|
||||||
|
if valid_facets_name.is_empty() {
|
||||||
|
return "this index does not have configured filterable attributes.".into();
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut result = String::new();
|
||||||
|
|
||||||
|
match invalid_facets_name.len() {
|
||||||
|
0 => (),
|
||||||
|
1 => write!(
|
||||||
|
result,
|
||||||
|
"attribute `{}` is not filterable.",
|
||||||
|
invalid_facets_name.first().unwrap()
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
_ => write!(
|
||||||
|
result,
|
||||||
|
"attributes `{}` are not filterable.",
|
||||||
|
invalid_facets_name.iter().map(AsRef::as_ref).collect::<Vec<&str>>().join(", ")
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
};
|
||||||
|
|
||||||
|
match valid_facets_name.len() {
|
||||||
|
1 => write!(
|
||||||
|
result,
|
||||||
|
" The available filterable attribute is `{}`.",
|
||||||
|
valid_facets_name.first().unwrap()
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
_ => write!(
|
||||||
|
result,
|
||||||
|
" The available filterable attributes are `{}`.",
|
||||||
|
valid_facets_name.iter().map(AsRef::as_ref).collect::<Vec<&str>>().join(", ")
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
/// A little macro helper to autogenerate From implementation that needs two `Into`.
|
/// A little macro helper to autogenerate From implementation that needs two `Into`.
|
||||||
/// Given the following parameters: `error_from_sub_error!(FieldIdMapMissingEntry => InternalError)`
|
/// Given the following parameters: `error_from_sub_error!(FieldIdMapMissingEntry => InternalError)`
|
||||||
/// the macro will create the following code:
|
/// the macro will create the following code:
|
||||||
|
@ -291,6 +291,7 @@ impl<'a> FacetDistribution<'a> {
|
|||||||
if !invalid_fields.is_empty() {
|
if !invalid_fields.is_empty() {
|
||||||
return Err(UserError::InvalidFacetsDistribution {
|
return Err(UserError::InvalidFacetsDistribution {
|
||||||
invalid_facets_name: invalid_fields.into_iter().cloned().collect(),
|
invalid_facets_name: invalid_fields.into_iter().cloned().collect(),
|
||||||
|
valid_facets_name: filterable_fields.into_iter().collect(),
|
||||||
}
|
}
|
||||||
.into());
|
.into());
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user