/** * Add a default <a href="MinimumShouldMatchContext.html#minimumshouldmatch">"minimumShouldMatch" constraint</a>. * * @param matchingClausesNumber A definition of the number of "should" clauses that have to match. * If positive, it is the number of clauses that have to match. * See <a href="MinimumShouldMatchContext.html#minimumshouldmatch-minimum">Definition of the minimum</a> * for details and possible values, in particular negative values. * @return {@code this}, for method chaining. */ default BooleanJunctionPredicateContext minimumShouldMatchNumber(int matchingClausesNumber) { return minimumShouldMatch() .ifMoreThan( 0 ).thenRequireNumber( matchingClausesNumber ) .end(); }
/** * Add a default <a href="MinimumShouldMatchContext.html#minimumshouldmatch">"minimumShouldMatch" constraint</a>. * * @param matchingClausesPercent A definition of the number of "should" clauses that have to match, as a percentage. * If positive, it is the percentage of the total number of "should" clauses that have to match. * See <a href="MinimumShouldMatchContext.html#minimumshouldmatch-minimum">Definition of the minimum</a> * for details and possible values, in particular negative values. * @return {@code this}, for method chaining. */ default BooleanJunctionPredicateContext minimumShouldMatchPercent(int matchingClausesPercent) { return minimumShouldMatch() .ifMoreThan( 0 ).thenRequirePercent( matchingClausesPercent ) .end(); }
/** * Add a default <a href="MinimumShouldMatchContext.html#minimumshouldmatch">"minimumShouldMatch" constraint</a>. * * @param matchingClausesPercent A definition of the number of "should" clauses that have to match, as a percentage. * If positive, it is the percentage of the total number of "should" clauses that have to match. * See <a href="MinimumShouldMatchContext.html#minimumshouldmatch-minimum">Definition of the minimum</a> * for details and possible values, in particular negative values. * @return {@code this}, for method chaining. */ default BooleanJunctionPredicateContext minimumShouldMatchPercent(int matchingClausesPercent) { return minimumShouldMatch() .ifMoreThan( 0 ).thenRequirePercent( matchingClausesPercent ) .end(); }
/** * Add a default <a href="MinimumShouldMatchContext.html#minimumshouldmatch">"minimumShouldMatch" constraint</a>. * * @param matchingClausesNumber A definition of the number of "should" clauses that have to match. * If positive, it is the number of clauses that have to match. * See <a href="MinimumShouldMatchContext.html#minimumshouldmatch-minimum">Definition of the minimum</a> * for details and possible values, in particular negative values. * @return {@code this}, for method chaining. */ default BooleanJunctionPredicateContext minimumShouldMatchNumber(int matchingClausesNumber) { return minimumShouldMatch() .ifMoreThan( 0 ).thenRequireNumber( matchingClausesNumber ) .end(); }
@Test public void minimumShouldMatch_error_negativeCeiling() { StubMappingSearchTarget searchTarget = indexManager.createSearchTarget(); SubTest.expectException( "minimumShouldMatch constraint with negative ignoreConstraintCeiling", () -> searchTarget.predicate().bool().minimumShouldMatch() .ifMoreThan( -1 ).thenRequireNumber( 1 ) ) .assertThrown() .isInstanceOf( IllegalArgumentException.class ) .hasMessageContaining( "'ignoreConstraintCeiling'" ) .hasMessageContaining( "must be positive or zero" ); SubTest.expectException( "minimumShouldMatch constraint with negative ignoreConstraintCeiling", () -> searchTarget.predicate().bool().minimumShouldMatch() .ifMoreThan( -1 ).thenRequirePercent( 50 ) ) .assertThrown() .isInstanceOf( IllegalArgumentException.class ) .hasMessageContaining( "'ignoreConstraintCeiling'" ) .hasMessageContaining( "must be positive or zero" ); }
@Test public void minimumShouldMatch_error_multipleConflictingCeilings() { StubMappingSearchTarget searchTarget = indexManager.createSearchTarget(); SubTest.expectException( "bool() predicate with minimumShouldMatch constraints with multiple conflicting ceilings", () -> searchTarget.predicate().bool().minimumShouldMatch() .ifMoreThan( 2 ).thenRequireNumber( -1 ) .ifMoreThan( 4 ).thenRequirePercent( 70 ) .ifMoreThan( 4 ).thenRequirePercent( 70 ) ) .assertThrown() .isInstanceOf( SearchException.class ) .hasMessageContaining( "Multiple conflicting minimumShouldMatch constraints for ceiling" ) .hasMessageContaining( "'4'" ); }
.ifMoreThan( 0 ).thenRequireNumber( 1 ) .ifMoreThan( 2 ).thenRequireNumber( -1 ) .ifMoreThan( 4 ).thenRequirePercent( 70 );
.ifMoreThan( 2 ).thenRequireNumber( -1 ) .ifMoreThan( 4 ).thenRequirePercent( 70 );