feat: Add contains-substring filter for String fields#3392
Conversation
|
🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review. Tip
Note Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect. Caution Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement. Our CI and AI review are safeguards, not development tools. If many issues are flagged, rethink your development approach. Invest more effort in planning and design rather than using review cycles to fix low-quality code. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds a new ChangesContains Substring Constraint
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant User as Dashboard User
participant Filter as Filters UI
participant Builder as addConstraintFromValues
participant Query as Parse.Query
User->>Filter: select "contains substring" constraint
Filter->>Builder: addConstraintFromValues(field, 'contains', value)
Builder->>Query: query.contains(field, String(value))
Query-->>Filter: returns matching records via escaped regex
Related Issues: Suggested labels: enhancement, filters Suggested reviewers: dblythy, mtrezza 🐰 A whisker twitches, sniffing through strings so tight, 🚥 Pre-merge checks | ✅ 6 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (6 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
I don't understand what this PR is trying to achieve? What's the purpose of adding a "contains" filter, which was removed in #2991 because it was just a subset of "matches regex"? |
|
Oh, I didn't realise this previously existed. I thought the ticket was about adding the FWIW Happy to close though if you prefer |
Closes #2153
Problem
For a String column, the only substring-style filter is matches regex, which passes the input to
Parse.Query#matchesverbatim as a regular expression. Regex metacharacters therefore have special meaning:.matches any character, and metacharacters like(are invalid on their own, so a plain literal search either returns the wrong rows or fails with a server error. There is no way to do a simple literal substring search.Fix
Add a separate contains substring operator for String fields, backed by the SDK's
Parse.Query#contains, which wraps the input in\Q...\Eso the whole value is matched literally (the same quotingstartsWith/endsWithalready use). The existing matches regex operator is unchanged, so raw regex remains available.The "rename the confusing operator" half of the issue was already handled in #2991 (the old mislabelled entry was replaced by the explicit matches regex), so this PR only adds the new safe operator. This does not touch the Array-field labels discussed in #2052.
Unit test added in
src/lib/tests/queryFromFilters.test.jscovering literal substring matching, metacharacter escaping, and a contrast assertingmatchesstays a raw regex.The new operator
The String field condition list now offers contains substring below matches regex:
Literal
.(data:a(b,c.d,hello,world)matches regex treats
.as a wildcard and returns every row:contains substring matches
.literally and returns onlyc.d:Literal
a(bmatches regex with
a(bis an invalid regular expression, so the query fails (500) and nothing is shown:contains substring with
a(bmatches the parenthesis literally and returns the correct row:Summary by CodeRabbit
New Features
Bug Fixes