Interface Constraint
- All Known Implementing Classes:
AllConstraint, AnyConstraint, BetweenConstraint, ContainsConstraint, ExistsConstraint, FacetConstraint, LookAheadConstraint, MatchConstraint, NoOpConstraint, NotConstraint, PathConstraint, QueryConstraint
public interface Constraint
Base interface for defining filter conditions (constraints) used in document search queries.
Constraints determine whether a given Document matches
specific criteria. Implementations of this interface can target paths, values, metadata,
or structural characteristics of the document.
Serialization
This interface uses Jackson’s@JsonTypeInfo with deduction, enabling automatic deserialization
of concrete types based on structure. If no recognizable subtype is matched, NoOpConstraint is used.
Subtypes include:
AllConstraint– Logical AND of multiple constraintsAnyConstraint– Logical OR of multiple constraintsMatchConstraint– Matches exact phrases or termsContainsConstraint– Substring matching on field valuesBetweenConstraint– Numeric or date range filteringExistsConstraint– Matches documents with a non-null value at a pathQueryConstraint– Full-text search syntax supporting wildcards and advanced logicNotConstraint– Negates a constraintLookAheadConstraint– Predictive phrase/word matching based on user typing, commonly used for user-facing document searchFacetConstraint– Filters based on field facets (used for drilldown/aggregation)
Composability
Constraints can be composed into larger expressions usingand(Constraint) and or(Constraint):
Constraint c = MatchConstraint.match("value", "path1")
.and(ExistsConstraint.exists("path2"))
.or(ContainsConstraint.contains("fragment", "description"));
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault Constraintand(Constraint other) Combines this constraint with another using logical AND.default ConstraintReturns a version of this constraint with all composite constraints decomposed into their atomic elements.booleanIndicates whether this constraint targets specific paths in the document.booleanEvaluates whether this constraint applies to the given document.default Constraintor(Constraint other) Combines this constraint with another using logical OR.
-
Method Details
-
matches
Evaluates whether this constraint applies to the given document.- Parameters:
document- the document to test- Returns:
trueif the constraint matches the document
-
hasPathConstraint
boolean hasPathConstraint()Indicates whether this constraint targets specific paths in the document.- Returns:
trueif path-based filtering is involved
-
decompose
Returns a version of this constraint with all composite constraints decomposed into their atomic elements.Useful for precomputing optimized structures (e.g. via
AllConstraintorAnyConstraint).- Returns:
- a simplified version of the constraint
-
and
Combines this constraint with another using logical AND.- Parameters:
other- the other constraint- Returns:
- a new
AllConstraintcombining both
-
or
Combines this constraint with another using logical OR.- Parameters:
other- the other constraint- Returns:
- a new
AnyConstraintcombining both
-