Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Search: solidify conversion to Zoekt queries #60349

Merged
merged 7 commits into from
Feb 9, 2024
Merged

Conversation

jtibshirani
Copy link
Member

@jtibshirani jtibshirani commented Feb 9, 2024

For the 'search-content-based-lang-detection' feature, this PR improves how filters are converted to Zoekt queries:

  • Only convert filters to Zoekt lang filters, instead of also including file filters
  • Handle excluded filters as well, for example -lang:go
  • Use 'and' instead of 'or' to combine multiple filters

Relates to https://github.com/sourcegraph/sourcegraph/issues/60341

Test plan

Added new unit tests, manual testing

func toLangFilters(langs []string) []zoekt.Q {
var filters []zoekt.Q
for _, lang := range langs {
lang, _ = enry.GetLanguageByAlias(lang) // Invariant: lang is valid.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know Go doesn't have built-in assertions and it's documented why, but I think it would be helpful to assert that the second return value is true to catch potential bugs.

Copy link
Member Author

@jtibshirani jtibshirani Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By "assert" do you mean check the value and return an error? Unfortunately that makes this quite verbose and less readable. For "runtime assertions", do we ever use panic? I haven't seen this used in our Go code, maybe it goes against the spirit of Go's design.

For now I didn't touch this (as it's a pre-existing issue) but would be interested in your thoughts!

Copy link
Contributor

@varungandhi-src varungandhi-src left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, left some minor suggestions and questions. 👍🏽

internal/search/zoekt/query_test.go Outdated Show resolved Hide resolved
Copy link
Member

@keegancsmith keegancsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

internal/search/zoekt/query.go Show resolved Hide resolved
@jtibshirani jtibshirani merged commit bec5621 into main Feb 9, 2024
15 checks passed
@jtibshirani jtibshirani deleted the jtibs/lang-filter branch February 9, 2024 17:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants