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

search jobs: support diff, commit and path search#60883

Merged
stefanhengl merged 8 commits intomainfrom
sh/search-jobs/support-diff-commit
Mar 11, 2024
Merged

search jobs: support diff, commit and path search#60883
stefanhengl merged 8 commits intomainfrom
sh/search-jobs/support-diff-commit

Conversation

@stefanhengl
Copy link
Member

@stefanhengl stefanhengl commented Mar 6, 2024

This adds support for diff, commit and path results types to Search Jobs. We also improve the error messages to be more helpful.

Here are a couple of examples of search queries which are now supported in addition to content search

  • diff search: author:alice after:"1 year ago" foo type:diff
  • commit search: bas type:commit
  • path search: file:search.go type:path

Notes:

  • For interactive search, the default types are path, file and repo. For Search Jobs, the default types are path and file, because we don't support repo search yet.
  • This change is fully backward compatible. The API does not change.

Test plan:

  • New and updated unit tests
  • I ran a couple diff/commit search jobs locally and compared the result counts with the counts returned by interactive search.

This addds support for diff, commit and path results types to Search
Jobs. Additionally we now allow multiple search types per search. For
example, a search job for the query "secret" will now return path and
content matches by default. Before we just returned content matches.

I also paid attention to improving the error messages, which relates to
feedback we received recently.

Notes:
- For interactive search, the default types are path, file and repo. For
search jobs, the default is path and file, because we don't support repo
search yet.

Test plan:
- new and updated unit tests
@cla-bot cla-bot bot added the cla-signed label Mar 6, 2024
@stefanhengl stefanhengl force-pushed the sh/search-jobs/support-diff-commit branch from e0e4e3f to 69cc104 Compare March 6, 2024 10:35
@stefanhengl stefanhengl requested a review from a team March 6, 2024 11:50
@stefanhengl stefanhengl marked this pull request as ready for review March 6, 2024 11:51
Copy link
Contributor

@jtibshirani jtibshirani left a comment

Choose a reason for hiding this comment

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

This looks good to me, I left some small comments/ questions as I learn how this works more deeply.

// This is OK for the EAP but we should remove the limitation soon.
if !strings.Contains(q, "type:file") {
q = "type:file " + q
if strings.Contains(q, "patterntype:structural") {
Copy link
Contributor

@jtibshirani jtibshirani Mar 6, 2024

Choose a reason for hiding this comment

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

I think we should do a case-insensitive comparison, since patternType:structural is common and valid as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

patterntype is hard coded in the client, but I agree, we shouldn't rely on it, especially if customers integrate with the API directly.


if len(inputs.Plan) != 1 {
return Exhaustive{}, errors.Errorf("expected a simple expression (no and/or/etc). Got multiple jobs to run %v", inputs.Plan)
return Exhaustive{}, errors.Errorf("Invalid query: Search Jobs only supports simple expressions. Use AND/OR for patterns but not for filters. Consider splitting into multiple subqueries and creating separate search jobs for each.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of saying "Use AND/OR for patterns but not for filters", maybe we could say "Search Jobs does not support using AND/ OR with filters", and give an example like file:.go or file:.rs? As a user I'd have some trouble understanding the current error.

@stefanhengl
Copy link
Member Author

Am I understanding right that we'd currently fail the entire job if one repo search errors?

Yes

@stefanhengl stefanhengl requested a review from jtibshirani March 7, 2024 11:25
It is currently possible to create search jobs based on `select:` queries although we don't support them. This adds a check to fail validation.

## Test plan
- updated unit test
@stefanhengl stefanhengl merged commit 586b391 into main Mar 11, 2024
@stefanhengl stefanhengl deleted the sh/search-jobs/support-diff-commit branch March 11, 2024 12:01
@jtibshirani jtibshirani mentioned this pull request Mar 13, 2024
5 tasks
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.

3 participants