Describe the bug
When creating a RegexFilter, flags from passed java.util.regex.Pattern are ignored.
To Reproduce
Create a query with a RegexFilter created from a java.regex.Pattern with CASE_INSENSITIVE flag set, for example:
Query<Unit> query = datastore.find(Unit.class);
String patternString = String.format(".*%s.*", searchString);
Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
query.filter(regex("name", pattern));
Perform the query with a string matching case-insensitively but not case-sensitively.
Expected behavior
Entity (matching case-insensitively) is returned.
Please complete the following information:
- Server Version: 4.4.28
- Driver Version: 5.6.1
- Morphia Version: 2.5.1
Additional context
In Morphia 1.3.2 the corresponding filter creation
Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
query.filter("name", pattern);
added case-insensitive option to regex in resulting query.
{ query: {"name": {"$regex": ".*any.*", "$options": "i"}} }
Workaround
Add case-insensitivity to the pattern string by prepending (?i).
Describe the bug
When creating a
RegexFilter, flags from passedjava.util.regex.Patternare ignored.To Reproduce
Create a query with a
RegexFiltercreated from ajava.regex.PatternwithCASE_INSENSITIVEflag set, for example:Perform the query with a string matching case-insensitively but not case-sensitively.
Expected behavior
Entity (matching case-insensitively) is returned.
Please complete the following information:
Additional context
In Morphia 1.3.2 the corresponding filter creation
added case-insensitive option to regex in resulting query.
{ query: {"name": {"$regex": ".*any.*", "$options": "i"}} }Workaround
Add case-insensitivity to the pattern string by prepending
(?i).