sourcegraph / sourcegraph-public-snapshot

Code AI platform with Code Search & Cody
https://sourcegraph.com
Other
10.1k stars 1.28k forks source link

Support searching indexed branches in searcher-zoekt client #17493

Closed rvantonder closed 3 years ago

rvantonder commented 3 years ago

In v1 of the searcher-zoekt client #17495, we currently hardcode a repo branch of HEAD for searches.

We need to make this more general:

I.e., I think we can actually just use Commit in api.CommitID to pass on branch information. But, from the frontend side, only unindexed repo/commit IDs will be forwarded to searcher currently.

github-actions[bot] commented 3 years ago

Heads up @lguychard - the "team/search" label was applied to this issue.

camdencheek commented 3 years ago

So, it appears that Zoekt only supports searching by branch name, not by commit. In the request to searcher, the branch names has already been resolved fully to a commit hash, which we can't use to query Zoekt. Any ideas on how to resolve this?

rvantonder commented 3 years ago

CC @keegancsmith. Off-the-cuff thought: we send the branch to searcher if that's our only option?

keegancsmith commented 3 years ago

Searcher client in textsearch.go should have access to the branch already (part of RepositoryRevision structure). By only sending the branch you avoid the need to resolve the commit (ie call gitserver) which makes this more scaleable. So you actually want to do that. See zoektIndexedRepos function for how we do it in the literal/regexp search path.

However, we can update Zoekt to do matching on "versions" (SHAs). But for scaleability this isn't needed and we should rely on branch name to avoid gitserver interactions. To support versions in zoekt: We have code like this as part of zoektIndexedRepos, so something similiar can live in how query.0Branch is converted into a matchtree: https://sourcegraph.com/github.com/sourcegraph/zoekt@41147eccb798a61e2ed11a737456c5b41cdb1caf/-/blob/matchtree.go?subtree=true#L820-829