Repository navigation
feat(search): support negating a RecordQuery for exclude filters - #1983
Conversation
|
The latest Buf updates on your PR. Results from workflow Buf CI / verify-proto (pull_request).
|
Signed-off-by: András Jáky <[email protected]>
d42933b to
4423880
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🟡 Changes recommended
Exclusion SQL for skills/domains/modules incorrectly AND-combines excluded IDs and names, which can fail to exclude records that match either criterion.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
Adds first-class “exclude” (negated) filtering to SearchService by introducing a negate flag on RecordQuery, routing negated queries into dedicated RecordFilters.Excluded fields, and compiling those exclusions to SQL using NOT EXISTS for joined/multi-valued fields and NULL-safe negation for nullable scalar columns.
Changes:
- Extend
RecordQuery(proto + generated stubs) withbool negateand update query-to-filter routing to populate exclusion filters. - Add SQL helpers for
NOT EXISTSand NULL-safe negation; implement GORM exclusion compilation via a newrecord_exclude.go. - Add/extend unit and integration tests covering excluded filters and NULL-survival semantics.
File summaries
| File | Description |
|---|---|
| server/types/search.go | Adds ExcludedRecordFilters and new Without* filter options to represent negated filters. |
| server/database/utils/wildcard.go | Introduces shared SQL builders for NOT EXISTS and NULL-safe negation. |
| server/database/utils/wildcard_test.go | Adds unit tests for the new SQL builder helpers. |
| server/database/utils/utils.go | Routes negated RecordQuery entries into Without* options and flips boolean query types under negation. |
| server/database/utils/utils_test.go | Adds tests ensuring negated queries populate RecordFilters.Excluded and booleans flip correctly. |
| server/database/gorm/record.go | Hooks exclusion compilation into the main query builder (handleFilterOptions). |
| server/database/gorm/record_exclude.go | Implements exclusion SQL compilation (NOT EXISTS for joins, NULL-safe NOT for nullable scalars). |
| server/database/gorm/record_exclude_test.go | Adds a white-box test to ensure negated description retains NULL rows. |
| server/database/database_test.go | Adds DB-level tests validating negated filters (skills, scalar fields, annotations, severities, NULL authors/description). |
| server/controller/search_test.go | Adds controller test ensuring negated queries are forwarded into excluded filters. |
| proto/agntcy/dir/search/v1/record_query.proto | Adds the negate field to the API contract. |
| api/search/v1/record_query.pb.go | Regenerated Go stubs to include the new Negate field/getter. |
Review details
Files not reviewed (1)
- api/search/v1/record_query.pb.go: Generated file
Suppressed comments (2)
server/database/gorm/record_exclude.go:195
- The module exclusion subquery currently ANDs the module_id and name predicates together. If both Excluded.ModuleIDs and Excluded.ModuleNames are set, this will fail to exclude records that match either one independently; the match predicates should be OR-combined inside the correlated NOT EXISTS.
inner := strings.Join(conditions, " AND ")
return query.Where(utils.BuildNotExistsCondition("modules", "ex", inner), args...)
server/database/gorm/record_exclude.go:171
- The domain exclusion subquery currently ANDs the ID condition with the name condition, which means a record is only excluded when a single domain row matches both constraints simultaneously. When both excluded IDs and excluded names are present, this should exclude records matching either constraint (ID OR name) while still correlating on record_cid.
inner := strings.Join(conditions, " AND ")
return query.Where(utils.BuildNotExistsCondition("domains", "ex", inner), args...)
- Files reviewed: 11/12 changed files
- Comments generated: 2
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Signed-off-by: András Jáky <[email protected]>
Summary
bool negatetoRecordQuerysoSearchServiceclients can express "does NOT match X" alongside the existing "matches X"NOT EXISTSsubquery rather than negating the include-pathJOIN— negating theJOINwould wrongly resurrect a record via an unrelated matching row (e.g. excluding skill "nlp" on a record with skills[nlp, python]must still exclude it, not match it via the "python" row)description,schema_version,oasf_created_at,authors), use a NULL-safeNOT(...)that retains NULL rows instead of silently dropping themVERIFIED,TRUSTED,SCAN_SAFE), flip the parsed bool rather than adding new storageMotivation
RecordQuerycould only express inclusion — "records that match value X". There was no way to express exclusion — "records that do NOT match value X" — which blocked tri-state filtering (include / exclude / off) in clients built onSearchService.Compatibility
Default
negate: falsepreserves current behavior exactly (wire- and behavior-compatible) — this is an additive, backward-compatible change.Validation
task linttask testCloses #1940