Skip to content
Snippets Groups Projects

search: hoist or-expressions heuristic

Merged Administrator requested to merge rvt/hoist-or-heuristic into master

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

Approval is optional

Merged by avatar (Jul 25, 2025 9:14pm UTC)

Merge details

  • Changes merged into master with 324168bc.
  • Deleted the source branch.

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Created by: codecov[bot]

    Codecov Report

    Merging #9760 into master will increase coverage by 0.01%. The diff coverage is 90.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%) :arrow_up:
    Impacted Files Coverage Δ
    internal/search/query/transformer.go 92.00% <90.47%> (-8.00%) :arrow_down:
Please register or sign in to reply
Loading