Class MatchConstraint

java.lang.Object
io.fluxcapacitor.common.api.search.constraints.PathConstraint
io.fluxcapacitor.common.api.search.constraints.MatchConstraint
All Implemented Interfaces:
Constraint

public class MatchConstraint extends PathConstraint
A constraint that matches indexed document values based on text equality or normalized phrase matching.

The MatchConstraint is commonly used to filter documents that contain a specific word, phrase, or exact value in one or more indexed fields.

Examples


 // Match documents where the "status" field is "open"
 Constraint constraint = MatchConstraint.match("open", "status");

 // Match across all indexed fields
 Constraint constraint = MatchConstraint.match("open");

 // Match across multiple fields with strict equality
 Constraint constraint = MatchConstraint.match("PENDING", true, "status", "state");
 

Path Handling

You can provide one or more paths to target specific fields in the document. If no paths are provided, the constraint will match anywhere in the document. Empty or null paths are filtered out automatically.

Matching Modes

The constraint supports two modes:
  • strict = true – uses exact string equality against the raw value of the entry.
  • strict = false (default) – uses normalized matching via SearchUtils.normalize(String) and compares to the asPhrase() form of the entry (used for full-text search).
See Also:
  • Constructor Details

    • MatchConstraint

      public MatchConstraint()
  • Method Details

    • match

      public static Constraint match(Object value, String... paths)
      Creates a constraint that performs non-strict (normalized) matching of the provided value across the specified paths.

      If no paths are given, the match will be applied across all indexed fields in the document.

      If the value is null, returns a NoOpConstraint. If the value is a Collection, creates a disjunction (AnyConstraint) of match constraints for each non-null element. If the value implements HasId, the getId() value is used for matching. For all other types, the value is converted to a string.

      Parameters:
      value - the value to match
      paths - the paths to search in (or empty for all fields)
      Returns:
      a Constraint instance or NoOpConstraint
    • match

      public static Constraint match(Object value, boolean strict, String... paths)
      Creates a constraint that matches the given value across the specified paths, with an option to enforce strict string equality.

      If no paths are given, the match will be applied across all indexed fields in the document.

      If the value is null, returns a NoOpConstraint. If the value is a Collection, creates a disjunction (AnyConstraint) of match constraints for each non-null element. If the value implements HasId, the getId() value is used for matching. For all other types, the value is converted to a string.

      Parameters:
      value - the value to match
      strict - if true, use exact string matching; if false, use normalized phrase match
      paths - the paths to search in (or empty for all fields)
      Returns:
      a Constraint instance or NoOpConstraint
    • matches

      protected boolean matches(Document.Entry entry)
      Description copied from class: PathConstraint
      Evaluates whether the specified document entry satisfies the condition defined by this method's implementation.
      Specified by:
      matches in class PathConstraint
      Parameters:
      entry - the document entry to evaluate
      Returns:
      true if the entry satisfies the condition; false otherwise
    • computeEntryMatcher

      protected Predicate<Document.Entry> computeEntryMatcher()