Interface BooleanPredicateOptionsCollector<S extends BooleanPredicateOptionsCollector<?>>

Type Parameters:
S - The "self" type (the actual exposed type of this collector).
All Known Subinterfaces:
BooleanPredicateClausesStep<S>, GenericBooleanPredicateClausesStep<S,C>

public interface BooleanPredicateOptionsCollector<S extends BooleanPredicateOptionsCollector<?>>
An object where the clauses and options of a boolean predicate can be set.

Different types of clauses have different effects, see below.

"must" clauses

"must" clauses are required to match: if they don't match, then the boolean predicate will not match.

Matching "must" clauses are taken into account during score computation.

"must not" clauses

"must not" clauses are required to not match: if they match, then the boolean predicate will not match.

"must not" clauses are ignored during score computation.

"filter" clauses

"filter" clauses are required to match: if they don't match, then the boolean predicate will not match.

"filter" clauses are ignored during score computation, and so are any clauses of boolean predicates contained in the filter clause (even "must" or "should" clauses).

"should" clauses

"should" clauses may optionally match, and are required to match depending on the context.

Matching "should" clauses are taken into account during score computation.

The exact behavior of `should` clauses is as follows:

  • When there isn't any "must" clause nor any "filter" clause in the boolean predicate, then at least one "should" clause is required to match. Simply put, in this case, the "should" clauses behave as if there was an "OR" operator between each of them.
  • When there is at least one "must" clause or one "filter" clause in the boolean predicate, then the "should" clauses are not required to match, and are simply used for scoring.
  • This behavior can be changed by specifying "minimumShouldMatch" constraints.
  • Method Details

    • with

      S with(Consumer<? super S> contributor)
      Delegates setting clauses and options to a given consumer.

      Best used with lambda expressions.

      Parameters:
      contributor - A consumer that will add clauses and options to the collector that it consumes. Should generally be a lambda expression.
      Returns:
      this, for method chaining.
    • must

      S must(SearchPredicate searchPredicate)
      Add a "must" clause based on a previously-built SearchPredicate.
      Parameters:
      searchPredicate - The predicate that must match.
      Returns:
      this, for method chaining.
    • mustNot

      S mustNot(SearchPredicate searchPredicate)
      Add a "must not" clause based on a previously-built SearchPredicate.
      Parameters:
      searchPredicate - The predicate that must not match.
      Returns:
      this, for method chaining.
    • should

      S should(SearchPredicate searchPredicate)
      Add a "should" clause based on a previously-built SearchPredicate.
      Parameters:
      searchPredicate - The predicate that should match.
      Returns:
      this, for method chaining.
    • filter

      S filter(SearchPredicate searchPredicate)
      Add a "filter" clause based on a previously-built SearchPredicate.
      Parameters:
      searchPredicate - The predicate that must match.
      Returns:
      this, for method chaining.
    • must

      default S must(PredicateFinalStep dslFinalStep)
      Add a "must" clause based on an almost-built SearchPredicate.
      Parameters:
      dslFinalStep - A final step in the predicate DSL allowing the retrieval of a SearchPredicate.
      Returns:
      this, for method chaining.
    • mustNot

      default S mustNot(PredicateFinalStep dslFinalStep)
      Add a "must not" clause based on an almost-built SearchPredicate.
      Parameters:
      dslFinalStep - A final step in the predicate DSL allowing the retrieval of a SearchPredicate.
      Returns:
      this, for method chaining.
    • should

      default S should(PredicateFinalStep dslFinalStep)
      Add a "should" clause based on an almost-built SearchPredicate.
      Parameters:
      dslFinalStep - A final step in the predicate DSL allowing the retrieval of a SearchPredicate.
      Returns:
      this, for method chaining.
    • filter

      default S filter(PredicateFinalStep dslFinalStep)
      Add a "filter" clause based on an almost-built SearchPredicate.
      Parameters:
      dslFinalStep - A final step in the predicate DSL allowing the retrieval of a SearchPredicate.
      Returns:
      this, for method chaining.
    • must

      S must(Function<? super SearchPredicateFactory,? extends PredicateFinalStep> clauseContributor)
      Add a "must" clause to be defined by the given function.

      Best used with lambda expressions.

      Parameters:
      clauseContributor - A function that will use the factory passed in parameter to create a predicate, returning the final step in the predicate DSL. Should generally be a lambda expression.
      Returns:
      this, for method chaining.
    • mustNot

      S mustNot(Function<? super SearchPredicateFactory,? extends PredicateFinalStep> clauseContributor)
      Add a "must not" clause to be defined by the given function.

      Best used with lambda expressions.

      Parameters:
      clauseContributor - A function that will use the factory passed in parameter to create a predicate, returning the final step in the predicate DSL. Should generally be a lambda expression.
      Returns:
      this, for method chaining.
    • should

      S should(Function<? super SearchPredicateFactory,? extends PredicateFinalStep> clauseContributor)
      Add a "should" clause to be defined by the given function.

      Best used with lambda expressions.

      Parameters:
      clauseContributor - A function that will use the factory passed in parameter to create a predicate, returning the final step in the predicate DSL. Should generally be a lambda expression.
      Returns:
      this, for method chaining.
    • filter

      S filter(Function<? super SearchPredicateFactory,? extends PredicateFinalStep> clauseContributor)
      Add a "filter" clause to be defined by the given function.

      Best used with lambda expressions.

      Parameters:
      clauseContributor - A function that will use the factory passed in parameter to create a predicate, returning the final step in the predicate DSL. Should generally be a lambda expression.
      Returns:
      this, for method chaining.
    • minimumShouldMatchNumber

      default S minimumShouldMatchNumber(int matchingClausesNumber)
      Parameters:
      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 Definition of the minimum for details and possible values, in particular negative values.
      Returns:
      this, for method chaining.
    • minimumShouldMatchPercent

      default S minimumShouldMatchPercent(int matchingClausesPercent)
      Parameters:
      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 Definition of the minimum for details and possible values, in particular negative values.
      Returns:
      this, for method chaining.
    • minimumShouldMatch

      MinimumShouldMatchConditionStep<? extends S> minimumShouldMatch()
      Start defining the minimum number of "should" constraints that have to match in order for the boolean predicate to match.

      See MinimumShouldMatchConditionStep.

      Returns:
      A MinimumShouldMatchConditionStep where constraints can be defined.
    • minimumShouldMatch

      S minimumShouldMatch(Consumer<? super MinimumShouldMatchConditionStep<?>> constraintContributor)
      Start defining the minimum number of "should" constraints that have to match in order for the boolean predicate to match.

      See MinimumShouldMatchConditionStep.

      Parameters:
      constraintContributor - A consumer that will add constraints to the DSL step passed in parameter. Should generally be a lambda expression.
      Returns:
      this, for method chaining.
    • hasClause

      boolean hasClause()
      Checks if this predicate contains at least one clause.
      Returns:
      true if any clauses were added, i.e. any of the must(..)/should(..)/mustNot(..)/filter(..) were called at least once, false otherwise.