Skip to content

Commit

Permalink
HSEARCH-3200 Extract common min should match options into reused inte…
Browse files Browse the repository at this point in the history
…rface
  • Loading branch information
marko-bekhta committed Apr 23, 2024
1 parent 1b7d671 commit ebec41f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
*
* @param <S> The "self" type (the actual exposed type of this collector).
*/
public interface BooleanPredicateOptionsCollector<S extends BooleanPredicateOptionsCollector<?>> {
public interface BooleanPredicateOptionsCollector<S extends BooleanPredicateOptionsCollector<?>>
extends CommonMinimumShouldMatchOptionsStep<S> {

/**
* Delegates setting clauses and options to a given consumer.
Expand Down Expand Up @@ -206,58 +207,6 @@ default S filter(PredicateFinalStep dslFinalStep) {
*/
S filter(Function<? super SearchPredicateFactory, ? extends PredicateFinalStep> clauseContributor);

/**
* Add a default <a href="MinimumShouldMatchConditionStep.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="MinimumShouldMatchConditionStep.html#minimumshouldmatch-minimum">Definition of the minimum</a>
* for details and possible values, in particular negative values.
* @return {@code this}, for method chaining.
*/
default S minimumShouldMatchNumber(int matchingClausesNumber) {
return minimumShouldMatch()
.ifMoreThan( 0 ).thenRequireNumber( matchingClausesNumber )
.end();
}

/**
* Add a default <a href="MinimumShouldMatchConditionStep.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="MinimumShouldMatchConditionStep.html#minimumshouldmatch-minimum">Definition of the minimum</a>
* for details and possible values, in particular negative values.
* @return {@code this}, for method chaining.
*/
default S minimumShouldMatchPercent(int matchingClausesPercent) {
return minimumShouldMatch()
.ifMoreThan( 0 ).thenRequirePercent( matchingClausesPercent )
.end();
}

/**
* Start defining the minimum number of "should" constraints that have to match
* in order for the boolean predicate to match.
* <p>
* See {@link MinimumShouldMatchConditionStep}.
*
* @return A {@link MinimumShouldMatchConditionStep} where constraints can be defined.
*/
MinimumShouldMatchConditionStep<? extends S> minimumShouldMatch();

/**
* Start defining the minimum number of "should" constraints that have to match
* in order for the boolean predicate to match.
* <p>
* See {@link MinimumShouldMatchConditionStep}.
*
* @param constraintContributor A consumer that will add constraints to the DSL step passed in parameter.
* Should generally be a lambda expression.
* @return {@code this}, for method chaining.
*/
S minimumShouldMatch(Consumer<? super MinimumShouldMatchConditionStep<?>> constraintContributor);

/**
* Checks if this predicate contains at least one clause.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.engine.search.predicate.dsl;

import java.util.function.Consumer;

import org.hibernate.search.engine.search.common.BooleanOperator;

/**
* The step in a predicate definition, where optional minimum should match parameters can be set.
*
* @param <S> The "self" type (the actual exposed type of this step).
*/
public interface CommonMinimumShouldMatchOptionsStep<S extends CommonMinimumShouldMatchOptionsStep<?>> {

/**
* Add a default <a href="MinimumShouldMatchConditionStep.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="MinimumShouldMatchConditionStep.html#minimumshouldmatch-minimum">Definition of the minimum</a>
* for details and possible values, in particular negative values.
* @return {@code this}, for method chaining.
*/
default S minimumShouldMatchNumber(int matchingClausesNumber) {
return minimumShouldMatch()
.ifMoreThan( 0 ).thenRequireNumber( matchingClausesNumber )
.end();
}

/**
* Add a default <a href="MinimumShouldMatchConditionStep.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="MinimumShouldMatchConditionStep.html#minimumshouldmatch-minimum">Definition of the minimum</a>
* for details and possible values, in particular negative values.
* @return {@code this}, for method chaining.
*/
default S minimumShouldMatchPercent(int matchingClausesPercent) {
return minimumShouldMatch()
.ifMoreThan( 0 ).thenRequirePercent( matchingClausesPercent )
.end();
}

MinimumShouldMatchConditionStep<? extends S> minimumShouldMatch();

/**
* Start defining the minimum number of "should" constraints that have to match
* in order for the boolean predicate to match.
* <p>
* See {@link MinimumShouldMatchConditionStep}.
*
* @return A {@link MinimumShouldMatchConditionStep} where constraints can be defined.
*/
S minimumShouldMatch(
Consumer<? super MinimumShouldMatchConditionStep<?>> constraintContributor);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*/
package org.hibernate.search.engine.search.predicate.dsl;

import java.util.function.Consumer;

import org.hibernate.search.engine.search.common.BooleanOperator;

/**
Expand All @@ -16,7 +14,7 @@
* @param <S> The "self" type (the actual exposed type of this step).
*/
public interface CommonQueryStringPredicateOptionsStep<S extends CommonQueryStringPredicateOptionsStep<?>>
extends PredicateFinalStep, PredicateScoreStep<S> {
extends PredicateFinalStep, PredicateScoreStep<S>, CommonMinimumShouldMatchOptionsStep<S> {

/**
* Define the default operator.
Expand Down Expand Up @@ -47,48 +45,4 @@ public interface CommonQueryStringPredicateOptionsStep<S extends CommonQueryStri
* @return {@code this}, for method chaining.
*/
S skipAnalysis();

/**
* Add a default <a href="MinimumShouldMatchConditionStep.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="MinimumShouldMatchConditionStep.html#minimumshouldmatch-minimum">Definition of the minimum</a>
* for details and possible values, in particular negative values.
* @return {@code this}, for method chaining.
*/
default S minimumShouldMatchNumber(int matchingClausesNumber) {
return minimumShouldMatch()
.ifMoreThan( 0 ).thenRequireNumber( matchingClausesNumber )
.end();
}

/**
* Add a default <a href="MinimumShouldMatchConditionStep.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="MinimumShouldMatchConditionStep.html#minimumshouldmatch-minimum">Definition of the minimum</a>
* for details and possible values, in particular negative values.
* @return {@code this}, for method chaining.
*/
default S minimumShouldMatchPercent(int matchingClausesPercent) {
return minimumShouldMatch()
.ifMoreThan( 0 ).thenRequirePercent( matchingClausesPercent )
.end();
}

MinimumShouldMatchConditionStep<? extends S> minimumShouldMatch();

/**
* Start defining the minimum number of "should" constraints that have to match
* in order for the boolean predicate to match.
* <p>
* See {@link MinimumShouldMatchConditionStep}.
*
* @return A {@link MinimumShouldMatchConditionStep} where constraints can be defined.
*/
S minimumShouldMatch(
Consumer<? super MinimumShouldMatchConditionStep<?>> constraintContributor);

}

0 comments on commit ebec41f

Please sign in to comment.