refactor: update error message format for filterable attributes

This commit is contained in:
CodeMan62 2025-03-19 23:57:40 +05:30
parent 041f635214
commit 15db203b7d
2 changed files with 1291 additions and 968 deletions

2188
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -441,41 +441,48 @@ fn format_invalid_filter_distribution(
invalid_facets_name: &BTreeSet<String>, invalid_facets_name: &BTreeSet<String>,
valid_patterns: &BTreeSet<String>, valid_patterns: &BTreeSet<String>,
) -> String { ) -> String {
if valid_patterns.is_empty() {
return "this index does not have configured filterable attributes.".into();
}
let mut result = String::new(); let mut result = String::new();
match invalid_facets_name.len() { if invalid_facets_name.is_empty() {
0 => (), if valid_patterns.is_empty() {
1 => write!( return "this index does not have configured filterable attributes.".into();
result, }
"attribute `{}` is not filterable.", } else {
invalid_facets_name.first().unwrap() match invalid_facets_name.len() {
) 1 => write!(
.unwrap(), result,
_ => write!( "Attribute `{}` is not filterable.",
result, invalid_facets_name.first().unwrap()
"attributes `{}` are not filterable.", )
invalid_facets_name.iter().map(AsRef::as_ref).collect::<Vec<&str>>().join(", ") .unwrap(),
) _ => write!(
.unwrap(), result,
}; "Attributes `{}` are not filterable.",
invalid_facets_name.iter().map(AsRef::as_ref).collect::<Vec<&str>>().join(", ")
)
.unwrap(),
};
}
match valid_patterns.len() { if valid_patterns.is_empty() {
1 => write!( if !invalid_facets_name.is_empty() {
result, write!(result, " This index does not have configured filterable attributes.").unwrap();
" The available filterable attribute pattern is `{}`.", }
valid_patterns.first().unwrap() } else {
) match valid_patterns.len() {
.unwrap(), 1 => write!(
_ => write!( result,
result, " Available filterable attributes patterns are: `{}`.",
" The available filterable attribute patterns are `{}`.", valid_patterns.first().unwrap()
valid_patterns.iter().map(AsRef::as_ref).collect::<Vec<&str>>().join(", ") )
) .unwrap(),
.unwrap(), _ => write!(
result,
" Available filterable attributes patterns are: `{}`.",
valid_patterns.iter().map(AsRef::as_ref).collect::<Vec<&str>>().join(", ")
)
.unwrap(),
}
} }
result result