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:

Composability

Constraints can be composed into larger expressions using and(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 Type
    Method
    Description
    default Constraint
    and(Constraint other)
    Combines this constraint with another using logical AND.
    default Constraint
    Returns a version of this constraint with all composite constraints decomposed into their atomic elements.
    boolean
    Indicates whether this constraint targets specific paths in the document.
    boolean
    matches(Document document)
    Evaluates whether this constraint applies to the given document.
    default Constraint
    or(Constraint other)
    Combines this constraint with another using logical OR.
  • Method Details

    • matches

      boolean matches(Document document)
      Evaluates whether this constraint applies to the given document.
      Parameters:
      document - the document to test
      Returns:
      true if the constraint matches the document
    • hasPathConstraint

      boolean hasPathConstraint()
      Indicates whether this constraint targets specific paths in the document.
      Returns:
      true if path-based filtering is involved
    • decompose

      default Constraint decompose()
      Returns a version of this constraint with all composite constraints decomposed into their atomic elements.

      Useful for precomputing optimized structures (e.g. via AllConstraint or AnyConstraint).

      Returns:
      a simplified version of the constraint
    • and

      default Constraint and(Constraint other)
      Combines this constraint with another using logical AND.
      Parameters:
      other - the other constraint
      Returns:
      a new AllConstraint combining both
    • or

      default Constraint or(Constraint other)
      Combines this constraint with another using logical OR.
      Parameters:
      other - the other constraint
      Returns:
      a new AnyConstraint combining both