N
- The type of the next context (returned by MinimumShouldMatchNonEmptyContext.end()
).public interface MinimumShouldMatchContext<N>
"minimumShouldMatch" constraints define a minimum number of "should" clauses that have to match in order for the boolean predicate to match.
The feature is similar, and will work identically, to
"Min Number Should Match"
in Solr or
minimum_should_match
in Elasticsearch.
The minimum may be defined either directly as a positive number, or indirectly as a negative number or positive or negative percentage representing a ratio of the total number of "should" clauses in this boolean predicate.
Here is how each type of input is interpreted:
In any case, if the computed minimum is 0 or less, or higher than the total number of "should" clauses, behavior is backend-specific (it may throw an exception, or produce unpredictable results, or fall back to some default behavior).
Multiple conditional constraints may be defined, only one of them being applied depending on the total number of "should" clauses.
Each constraint is attributed a minimum number of "should" clauses that have to match, and an additional number. The additional number is unique to each constraint.
The additional number will be compared to the total number of "should" clauses, and the one closest while still strictly lower will be picked: its associated constraint will be applied. If no number matches, the minimum number of matching "should" clauses will be set to the total number of "should" clauses.
Examples:
// Example 1: at least 3 "should" clauses have to match
booleanContext1.minimumShouldMatchNumber( 3 );
// Example 2: at most 2 "should" clauses may not match
booleanContext2.minimumShouldMatchNumber( -2 );
// Example 3: at least 75% of "should" clauses have to match (rounded down)
booleanContext3.minimumShouldMatchPercent( 75 );
// Example 4: at most 25% of "should" clauses may not match (rounded down)
booleanContext4.minimumShouldMatchPercent( -25 );
// Example 5: if there are 3 "should" clauses or less, all "should" clauses have to match.
// If there are 4 "should" clauses or more, at least 90% of "should" clauses have to match (rounded down).
booleanContext5.minimumShouldMatchPercent( 3, 90 );
// Example 6: if there are 4 "should" clauses or less, all "should" clauses have to match.
// If there are 5 to 9 "should" clauses, at most 25% of "should" clauses may not match (rounded down).
// If there are 10 "should" clauses or more, at most 3 "should" clauses may not match.
booleanContext6.minimumShouldMatch()
.ifMoreThan( 4 ).thenRequirePercent( 25 )
.ifMoreThan( 9 ).thenRequireNumber( -3 )
.end();
Modifier and Type | Method and Description |
---|---|
MinimumShouldMatchConditionContext<N> |
ifMoreThan(int ignoreConstraintCeiling)
Start adding a "minimumShouldMatch" constraint that will be applied
if (and only if) there are strictly more than
ignoreConstraintCeiling "should" clauses. |
MinimumShouldMatchConditionContext<N> ifMoreThan(int ignoreConstraintCeiling)
ignoreConstraintCeiling
"should" clauses.
See Conditional constraints for the detailed rules defining whether a constraint is applied or not.
ignoreConstraintCeiling
- The number of "should" clauses above which the constraint
will cease to be ignored.ignoreConstraintCeiling
"should" clauses.Copyright © 2006-2019 Red Hat, Inc. and others. Licensed under the GNU Lesser General Public License (LGPL), version 2.1 or later.