mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 11:57:07 +02:00
Add a test on filterable attributes rules priority
**Changes:** - Add a new test playing with filterable attributes rules priority - Optimize the faceted field selector avoiding to match false positives
This commit is contained in:
parent
a7a62e5e4c
commit
5fa4b5c50a
2 changed files with 154 additions and 6 deletions
|
@ -342,15 +342,30 @@ fn match_pattern_by_features(
|
|||
filter: &impl Fn(&FilterableAttributesFeatures) -> bool,
|
||||
) -> PatternMatch {
|
||||
let mut selection = PatternMatch::NoMatch;
|
||||
|
||||
// `can_match` becomes false if the field name matches (PatternMatch::Match) any pattern that is not facet searchable or filterable,
|
||||
// this ensures that the field doesn't match a pattern with a lower priority, however it can still match a pattern for a nested field as a parent (PatternMatch::Parent).
|
||||
// See the test `search::filters::test_filterable_attributes_priority` for more details.
|
||||
let mut can_match = true;
|
||||
|
||||
// Check if the field name matches any pattern that is facet searchable or filterable
|
||||
for pattern in filterable_attributes {
|
||||
let features = pattern.features();
|
||||
if filter(&features) {
|
||||
match pattern.match_str(field_name) {
|
||||
PatternMatch::Match => return PatternMatch::Match,
|
||||
PatternMatch::Parent => selection = PatternMatch::Parent,
|
||||
PatternMatch::NoMatch => (),
|
||||
match pattern.match_str(field_name) {
|
||||
PatternMatch::Match => {
|
||||
let features = pattern.features();
|
||||
if filter(&features) && can_match {
|
||||
return PatternMatch::Match;
|
||||
} else {
|
||||
can_match = false;
|
||||
}
|
||||
}
|
||||
PatternMatch::Parent => {
|
||||
let features = pattern.features();
|
||||
if filter(&features) {
|
||||
selection = PatternMatch::Parent;
|
||||
}
|
||||
}
|
||||
PatternMatch::NoMatch => (),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue