Search backend: add support for negated predicates#40283
Conversation
|
Codenotify: Notifying subscribers in CODENOTIFY files for diff a8b4a34...edaba2d.
|
c1d2560 to
231576d
Compare
internal/search/query/predicate.go
Outdated
There was a problem hiding this comment.
This felt like the cleanest way of supporting negation in predicates. It allows each predicate to control whether it errors when negated, and we also already use this method to validate predicates during the validation step. It does somewhat blur the line between parsing, validation, and concrete representations, but I think we were actually already there. I renamed this to Unmarshal() from Parse() to reflect this.
internal/search/query/validate.go
Outdated
There was a problem hiding this comment.
This was the blanket "predicates do not support negation" error that is no longer needed.
rvantonder
left a comment
There was a problem hiding this comment.
needs changelog entry, yes? closes https://github.com/sourcegraph/sourcegraph/issues/24325 yes?
ah, yep. I've got some changelog debt from predicates changes.
Sure enough. I forgot we had an issue for this |
98a876c to
1e478e5
Compare
847b659 to
afc59b8
Compare
afc59b8 to
b33fa08
Compare
b33fa08 to
4176d99
Compare
43f5fab to
4176d99
Compare
| // Unmarshal parses the contents of the predicate arguments | ||
| // into the predicate object. | ||
| ParseParams(string) error | ||
| Unmarshal(params string, negated bool) error |
There was a problem hiding this comment.
Interface change: ParseParams is now Unmarshal to reflect the standard go idiom of mutating the struct being unmarshalled into. Additionally, at the point we unmarshal, we also store whether the predicate was negated (or error if not negated).
| - A new [multi-version upgrade](https://docs.sourcegraph.com/admin/updates#multi-version-upgrades) process now allows Sourcegraph instances to upgrade more than a single minor version. Instances at version 3.20 or later can now jump directly to 4.0. [#40628](https://github.com/sourcegraph/sourcegraph/pull/40628) | ||
| - Matching ranges in file paths are now highlighted for path results and content results. [#41296](https://github.com/sourcegraph/sourcegraph/pull/41296) [#41385](https://github.com/sourcegraph/sourcegraph/pull/41385) | ||
| - Aggregations by repository, file, author, and capture group are now provided for search results. [#39643](https://github.com/sourcegraph/sourcegraph/issues/39643) | ||
| - Negation support for the search predicates `-repo:has.path()` and `-repo:has.content()`. [#40283](https://github.com/sourcegraph/sourcegraph/pull/40283) |
There was a problem hiding this comment.
Note that the changelog does not include repo:has.tag() and repo:has(key:val) because those have not been announced/released yet, and will be tagged as experimental features for 4.0.
|
Re-requesting review because this got a little stale and getting it updated required non-trivial changes. |
rvantonder
left a comment
There was a problem hiding this comment.
Cool! Curious to test on Sourcegraph.com to get a sense of how well this behaves :-)
For most of our predicates, we can theoretically support negation. Up until now, we've explicitly disallowed negating predicates because their implementation (expanding the predicate in the query) was not performant enough to work at all unless the negation somehow excluded almost everything (
-repo:contains.file(.*)?).Now that we implement all our predicates natively, negation is actually within reach. In fact, when I rewrote our predicates, I rewrote most of them with negation in mind, so it's not a super big lift to start enabling it.
This PR removes the "predicates are not allowed to be negated" rule and enables negation for
repo:contains.file(),repo:contains.content(),repo:has(key:value), andrepo:has.tag(t).Stacked on https://github.com/sourcegraph/sourcegraph/pull/40280
Closes #24325
Fixes https://github.com/sourcegraph/sourcegraph/issues/41475
Test plan
Added many integration tests. Manually tested with local repo set.