search: hoist or-expressions heuristic
Created by: rvantonder
This PR introduces a transformer to convert ambiguous queries like
repo:foo a or b
to repo:foo (a or b)
instead of the grammar spec (repo:foo a) or b
. You may be familiar with the related slack thread.
In addition to arguments that this feels more natural to some (perhaps majority), what's far more important is the human view of visual consistency that this imposes (as opposed to grammatical consistency). Here's why: we will currently parse
repo:foo a and b
as (repo:foo a) and b
but because we treat whitespace between certain expressions implicitly as and
, the interpretation here is rather:
repo:foo a and b
== repo:foo and a and b
== (repo:foo a) and b
== repo:foo (a and b)
, so there is no ambiguity (rather, it is the case that syntactically (repo:foo a) and b
is kind of bogus, but we don't enforce that yet and just overlook it). Hence, as a user, you may experience:
repo:foo a and b
=> "hey this works"
repo:foo a or b
=> "?? why do I get an error?"
So, the above or
-expression will be rewritten in simple cases, see comment description of heuristic.
This PR does not apply the heuristic anywhere. The decision to apply it rests in other logic, that comes in follow up PR: #9761
Merge request reports
Activity
Created by: codecov[bot]
Codecov Report
Merging #9760 into master will increase coverage by
0.01%
. The diff coverage is90.47%
.@@ Coverage Diff @@ ## master #9760 +/- ## ========================================== + Coverage 41.96% 41.97% +0.01% ========================================== Files 1339 1339 Lines 73593 73614 +21 Branches 6626 6626 ========================================== + Hits 30880 30899 +19 - Misses 39869 39870 +1 - Partials 2844 2845 +1
Flag Coverage Δ #unit 41.97% <90.47%> (+0.01%)
Impacted Files Coverage Δ internal/search/query/transformer.go 92.00% <90.47%> (-8.00%)