search: fix type:repo behavior
Created by: rvantonder
Addresses https://github.com/sourcegraph/sourcegraph/issues/19239.
This is a fairly complex and intentional behavioral change to type:repo
. Considering it was basically broken for 3 months on Sourcegraph.com and hindering unfamiliar users I'm pretty aggressive about the behavioral changes here.
type:repo
do before?
What did When it did work, it would behave roughly as:
-
type:repo foo bar
meansrepo:"foo bar"
. I.e., if a user typedtype:repo facebook react
they are basically guaranteed to not get any results on Sourcegraph.com, since hardly any repos on GH contain a space (zero?) -
type:repo foo bar
in regex mode meansrepo:foo.*bar
, as we take the convention of interpolating.*
for spaces in regex mode.
type:repo
do now?
What does There's a comment in the code, but basically:
-
type:repo any thing
is translated torepo:any repo:thing
. This means we will do anand
search for space-separated patterns (as opposed to content searches, where spaces are significant for ordering). Theand
search is more suited when the user expects to search for repositories containing all these keywords.type:repo facebook react
will give a lot of results (not necessarily the order we want, but we'll get hits). -
type:repo a or not b
is translated torepo:a or -repo:b
. Basically, anyand
oror
operator is preserved when translating patterns with arepo:
prefix, and additionally,not
works as is -
caveat: because of the complex behavior must restrict the use of
type:repo
to only allowtype:repo
in isolation, it cannot be combined with othertype:
queries. I.e.,(type:repo or type:file) an example
is not supported. This because we wanttype:repo
to interpret "the rest" of the query at translation stage different to any other query shape, where other query shapes are understood as ordered patterns as-is, or otherwise rely on whatever inlined behavior we have elsewhere in the backend). It's not that it's not supportable. It's that it would take me 2 weeks+ to modify parsing so that it now takes into account context from something liketype
within a particular scope, which I would prefer not exist in the first place.