Class ContainsConstraint
- All Implemented Interfaces:
Constraint
This constraint can simulate different types of text searches based on the configuration:
prefixSearch = true
: Matches entries that end with the phrase (e.g.,*day
matches "Monday", "Tuesday").postfixSearch = true
: Matches entries that start with the phrase (e.g.,mon*
matches "Monday", "Monster").- Both
prefixSearch
andpostfixSearch
: Matches entries that contain the phrase anywhere (e.g.,*mon*
matches "Monday", "Common", "Commoner"). - Both
prefixSearch
andpostfixSearch
disabled (default): Matches the full word exactly as it appears (normalized and case-insensitive).
If splitInTerms
is true, the input phrase is split into individual normalized terms, and each term is
matched independently using the same search behavior. All terms must be found in the same document entry for the
match to succeed.
Matching is performed against the normalized form of each document entry using regular expressions if filtering is done in-memory. When using Flux Platform, this constraint is evaluated directly within the backing data store whenever possible.
If no paths are provided, the constraint matches all paths within the document.
Performance Considerations
-
Terms using a prefix or postfix wildcard (e.g.,
user*
or*name
) are resolved at the data store level and typically fast. -
Terms using both prefix and postfix wildcards (e.g.,
*log*
) are not natively supported by the backend and require in-memory filtering, which can be slow for large result sets. -
Similarly, prefix or postfix matches with terms shorter than 3 characters are also evaluated in-memory.
Note: This limitation does not apply to complete word matches (i.e., without wildcards). For example,"to"
as an exact term is efficient, butto*
or*to
are not. - When possible, prefer longer terms and structure queries to enable efficient execution via the underlying document store.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Constraint
contains
(String phrase, boolean prefixSearch, boolean postfixSearch, boolean splitInTerms, String... paths) Create a constraint that optionally splits the input phrase into individual terms and combines the resulting constraints usingAllConstraint
.static Constraint
Create a constraint that allows prefix and/or postfix matching of a given phrase.static Constraint
Create a basicContainsConstraint
that checks if the given phrase exists anywhere in the entry, using default full-word matching (i.e., neither prefix nor postfix logic).protected boolean
matches
(Document.Entry entry) Checks whether a single document entry matches the constraint.Methods inherited from class io.fluxcapacitor.common.api.search.constraints.PathConstraint
checkPathBeforeEntry, getPaths, hasPathConstraint, matches, withPaths
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.common.api.search.Constraint
and, decompose, or
-
Constructor Details
-
ContainsConstraint
public ContainsConstraint()
-
-
Method Details
-
contains
Create a basicContainsConstraint
that checks if the given phrase exists anywhere in the entry, using default full-word matching (i.e., neither prefix nor postfix logic).- Parameters:
phrase
- the phrase to matchpaths
- optional field paths to restrict the search to- Returns:
- a
Constraint
that matches if the phrase is found
-
contains
public static Constraint contains(String phrase, boolean prefixSearch, boolean postfixSearch, String... paths) Create a constraint that allows prefix and/or postfix matching of a given phrase.This provides fine-grained control over how terms are matched:
prefixSearch = true
: allows matches at the start of wordspostfixSearch = true
: allows matches at the end of words
- Parameters:
phrase
- the phrase to matchprefixSearch
- whether to allow entries that end with the phrase, e.g.: *hatpostfixSearch
- whether to allow entries that start with the phrase, e.g.: hat*paths
- optional field paths to restrict the match to- Returns:
- a
Constraint
using the specified match settings
-
contains
public static Constraint contains(String phrase, boolean prefixSearch, boolean postfixSearch, boolean splitInTerms, String... paths) Create a constraint that optionally splits the input phrase into individual terms and combines the resulting constraints usingAllConstraint
.This is especially useful when you want all words in a multi-word search query to be matched.
- Parameters:
phrase
- the full phrase to optionally split and matchprefixSearch
- whether to allow entries that end with the phrase, e.g.: *hatpostfixSearch
- whether to allow entries that start with the phrase, e.g.: hat*splitInTerms
- iftrue
, splits the phrase into individual normalized termspaths
- optional field paths to restrict the match- Returns:
- a compound
AllConstraint
if multiple terms, or a singleContainsConstraint
-
matches
Checks whether a single document entry matches the constraint. The entry is converted to a normalized phrase string, and the compiled regular expression is applied.- Specified by:
matches
in classPathConstraint
- Parameters:
entry
- the document entry- Returns:
true
if the entry matches the pattern, otherwisefalse
-