mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 04:17:10 +02:00
fix: improve error messages for filterable attributes and fix formatting
This commit is contained in:
parent
1f67f373d1
commit
3acf036526
9 changed files with 138 additions and 70 deletions
|
@ -1,8 +1,8 @@
|
|||
use std::collections::BTreeSet;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::Infallible;
|
||||
use std::fmt::Write;
|
||||
use std::{io, str};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use bstr::BString;
|
||||
use heed::{Error as HeedError, MdbError};
|
||||
|
@ -79,7 +79,7 @@ pub enum InternalError {
|
|||
#[error(transparent)]
|
||||
ArroyError(#[from] arroy::Error),
|
||||
#[error(transparent)]
|
||||
VectorEmbeddingError(#[from] crate::vector::Error)
|
||||
VectorEmbeddingError(#[from] crate::vector::Error),
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
|
|
|
@ -379,15 +379,16 @@ impl<'a> FacetDistribution<'a> {
|
|||
) -> Result<()> {
|
||||
let mut invalid_facets = BTreeSet::new();
|
||||
let mut matching_rule_indices = HashMap::new();
|
||||
|
||||
|
||||
if let Some(facets) = &self.facets {
|
||||
for field in facets.keys() {
|
||||
let matched_rule = matching_features(field, filterable_attributes_rules);
|
||||
let is_filterable = matched_rule.map_or(false, |(_, features)| features.is_filterable());
|
||||
|
||||
let is_filterable =
|
||||
matched_rule.map_or(false, |(_, features)| features.is_filterable());
|
||||
|
||||
if !is_filterable {
|
||||
invalid_facets.insert(field.to_string());
|
||||
|
||||
|
||||
// If the field matched a rule but that rule doesn't enable filtering,
|
||||
// store the rule index for better error messages
|
||||
if let Some((rule_index, _)) = matched_rule {
|
||||
|
|
|
@ -76,8 +76,9 @@ impl<'a> SearchForFacetValues<'a> {
|
|||
|
||||
let filterable_attributes_rules = index.filterable_attributes_rules(rtxn)?;
|
||||
let matched_rule = matching_features(&self.facet, &filterable_attributes_rules);
|
||||
let is_facet_searchable = matched_rule.map_or(false, |(_, features)| features.is_facet_searchable());
|
||||
|
||||
let is_facet_searchable =
|
||||
matched_rule.map_or(false, |(_, features)| features.is_facet_searchable());
|
||||
|
||||
if !is_facet_searchable {
|
||||
let matching_field_names =
|
||||
filtered_matching_patterns(&filterable_attributes_rules, &|features| {
|
||||
|
@ -85,7 +86,7 @@ impl<'a> SearchForFacetValues<'a> {
|
|||
});
|
||||
let (valid_patterns, hidden_fields) =
|
||||
index.remove_hidden_fields(rtxn, matching_field_names)?;
|
||||
|
||||
|
||||
// Get the matching rule index if any rule matched the attribute
|
||||
let matching_rule_index = matched_rule.map(|(rule_index, _)| rule_index);
|
||||
|
||||
|
|
|
@ -191,8 +191,9 @@ impl<'a> Search<'a> {
|
|||
let filterable_fields = ctx.index.filterable_attributes_rules(ctx.txn)?;
|
||||
// check if the distinct field is in the filterable fields
|
||||
let matched_rule = matching_features(distinct, &filterable_fields);
|
||||
let is_filterable = matched_rule.map_or(false, |(_, features)| features.is_filterable());
|
||||
|
||||
let is_filterable =
|
||||
matched_rule.map_or(false, |(_, features)| features.is_filterable());
|
||||
|
||||
if !is_filterable {
|
||||
// if not, remove the hidden fields from the filterable fields to generate the error message
|
||||
let matching_patterns =
|
||||
|
@ -201,10 +202,10 @@ impl<'a> Search<'a> {
|
|||
});
|
||||
let (valid_patterns, hidden_fields) =
|
||||
ctx.index.remove_hidden_fields(ctx.txn, matching_patterns)?;
|
||||
|
||||
|
||||
// Get the matching rule index if any rule matched the attribute
|
||||
let matching_rule_index = matched_rule.map(|(rule_index, _)| rule_index);
|
||||
|
||||
|
||||
// and return the error
|
||||
return Err(Error::UserError(UserError::InvalidDistinctAttribute {
|
||||
field: distinct.clone(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue