Class MatchConstraint
- All Implemented Interfaces:
Constraint
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 viaSearchUtils.normalize(String)and compares to theasPhrase()form of the entry (used for full-text search).
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Predicate<Document.Entry> static ConstraintCreates a constraint that matches the given value across the specified paths, with an option to enforce strict string equality.static ConstraintCreates a constraint that performs non-strict (normalized) matching of the provided value across the specified paths.protected booleanmatches(Document.Entry entry, Document document) Evaluates whether the specified document entry satisfies the condition defined by this method's implementation.Methods inherited from class PathConstraint
checkPathBeforeEntry, getPaths, hasPathConstraint, matches, withPathsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Constraint
and, decompose, or
-
Constructor Details
-
MatchConstraint
public MatchConstraint()
-
-
Method Details
-
match
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 aNoOpConstraint. If the value is aCollection, creates a disjunction (AnyConstraint) of match constraints for each non-null element. If the value implementsHasId, thegetId()value is used for matching. For all other types, the value is converted to a string.- Parameters:
value- the value to matchpaths- the paths to search in (or empty for all fields)- Returns:
- a
Constraintinstance orNoOpConstraint
-
match
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 aNoOpConstraint. If the value is aCollection, creates a disjunction (AnyConstraint) of match constraints for each non-null element. If the value implementsHasId, thegetId()value is used for matching. For all other types, the value is converted to a string.- Parameters:
value- the value to matchstrict- iftrue, use exact string matching; iffalse, use normalized phrase matchpaths- the paths to search in (or empty for all fields)- Returns:
- a
Constraintinstance orNoOpConstraint
-
matches
Description copied from class:PathConstraintEvaluates whether the specified document entry satisfies the condition defined by this method's implementation.- Specified by:
matchesin classPathConstraint- Parameters:
entry- the document entry to evaluate- Returns:
trueif the entry satisfies the condition;falseotherwise
-
computeEntryMatcher
-