From c652d8b9e882d2cff489d67c07a2d5066515fd43 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:13:33 +0000 Subject: [PATCH 1/5] Add search query quick reference and fix broken query examples Add a Quick reference section to the search query syntax page, adapted from the Code Search cheat sheet and verified on sourcegraph.sourcegraph.com: scope/narrow/version/find, common patterns and filters, and branch and tag searches, which need a repo: filter. Fix examples that failed verification: the file:has.owner filter name, the (open|close)file typo, the has.topic and has.contributor link targets, rev:at.time and before:/after: examples that were invalid on their own, the vscode default branch, the revision glob links to a repository that no longer exists, and the Search Jobs all-branches query. Amp-Thread-ID: https://ampcode.com/threads/T-1f043295-17f3-4f30-b014-ca3aff6606c2 Co-authored-by: Amp --- docs/code-search/queries/index.mdx | 161 ++++++++++++++++++------- docs/code-search/types/search-jobs.mdx | 2 +- 2 files changed, 118 insertions(+), 45 deletions(-) diff --git a/docs/code-search/queries/index.mdx b/docs/code-search/queries/index.mdx index 5d8ad434d..9586500d2 100644 --- a/docs/code-search/queries/index.mdx +++ b/docs/code-search/queries/index.mdx @@ -4,13 +4,86 @@ This page describes the query syntax for Code Search.

-A typical search consists of two parts: - -- A [search pattern](#search-patterns) containing the terms you want to search, for example `println` -- [Search filters](#filters-all-searches) that scope the search to certain repositories, languages, etc., for example `lang:java` +A typical search combines a [search pattern](#search-patterns), the terms you want to find, with [search filters](#filters-all-searches) that limit where Sourcegraph looks. Filters and patterns can appear in any order. For a graphical view of Sourcegraph's query syntax, see the [search language reference](/code-search/queries/language). +## Quick reference + +Most queries combine up to four parts: + +1. **Scope**: choose the repositories to search, for example `repo:my-org/payments`. +2. **Narrow**: filter by language, file path, or result type, for example `lang:go -file:test`. +3. **Version**: choose a branch, tag, or commit, for example `rev:develop`. +4. **Find**: describe what to match, for example `"deprecatedAPI"`. + +```sgquery +repo:my-org/payments lang:go -file:test rev:develop "deprecatedAPI" +``` + +In these examples, replace `my-org`, `my-repo`, `payments`, and the branch and tag names with names from your Sourcegraph instance. + +### Find code + +| To find | Query | +| ------------------------------------------ | ----------------------------------------------- | +| Files that contain all terms, in any order | `authentication middleware` | +| An exact phrase | `"authentication failed"` | +| A regular expression | `/auth.*failed/` | +| A combination of terms | `(error OR exception) AND retry NOT deprecated` | +| Text in exactly this case | `APIKey case:yes` | + +### Narrow the search + +| To search | Query | +| ---------------------------------------------- | ---------------------------------------- | +| One repository | `repo:^github\.com/my-org/my-repo$` | +| Repositories that match a pattern, except some | `repo:my-org/ -repo:legacy` | +| Files in repositories that contain a path | `repo:has.path(\.py) file:Dockerfile` | +| Repositories with recent commits | `repo:has.commit.after(1 month ago)` | +| One language | `lang:typescript` | +| All languages except one | `"authentication failed" -lang:markdown` | +| Symbol definitions | `type:symbol UserService` | +| Files with an extension that contain a pattern | `file:\.py$ file:has.content(TODO)` | + +`repo:` and `file:` take regular expressions, so `repo:my-org/my-repo` also matches `my-org/my-repo-legacy`. Use `^` and `$` to match one repository. The argument of `file:has.content(...)` is also a regular expression, and quotes in it are matched literally: `file:has.content("TODO")` matches only files that contain `"TODO"` with the quotes. + +Sourcegraph combines filters with `AND`, so you don't need an operator between them. For example, to find `authentication failed` in Node.js repositories, excluding generated and vendored code: + +```sgquery +repo:has.path(package.json) -file:(generated|vendor|dist|node_modules) "authentication failed" +``` + +To list recently active Go repositories that contain a Dockerfile: + +```sgquery +repo:has.path(Dockerfile) repo:has.commit.after(3 months ago) lang:go select:repo +``` + +### Search branches and tags + +Sourcegraph searches each repository's default branch unless the query has a `rev:` filter. A `rev:` filter needs a `repo:` filter in the same query. On its own, a query such as `rev:develop` returns an `Invalid syntax` alert that asks for a `repo:` filter. + +| To search | Query | +| ------------------------ | --------------------------------------- | +| A branch, tag, or commit | `repo:my-org/my-repo rev:release-1.0` | +| The default branch | `repo:my-org/my-repo rev:HEAD` | +| All branches | `repo:my-org/my-repo rev:*refs/heads/*` | +| All tags | `repo:my-org/my-repo rev:*refs/tags/*` | + +For example, to find `authentication` on every branch of the repositories that match `payments`: + +```sgquery +repo:payments rev:*refs/heads/* authentication +``` + +If some repositories that match `repo:` don't have the revision, Sourcegraph searches the others and lists the missing revisions under **Some revisions could not be searched**. To search several revisions at once, exclude branches, or use commit hashes, see [repository revisions](#repository-revisions). + +### Saved scopes and large searches + +- [Search contexts](/code-search/working/search-contexts) save a set of repositories and revisions. Select one with `context:`, for example `context:global`, which searches all repositories on the instance. +- [Search Jobs](/code-search/types/search-jobs) run a search in the background across many repositories, branches, or very large result sets, without the timeouts and result limits of interactive search, then let you download the results. + ## Search patterns This section documents the search pattern syntax in Sourcegraph. To match file content, you need to specify a search pattern. Search patterns are optional when searching [commits](#filters-diff-and-commit-searches-only), [filenames](#filename-search), or [repository names](#repository-name-search). @@ -63,34 +136,34 @@ Clicking the (.\*) toggle interprets all search patterns as regular expressions. The following filters can be used on all searches (using [RE2 syntax](https://golang.org/s/re2syntax) any place a regex is accepted): -| **Filters** | **Description** | **Examples** | -| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| **repo:regexp-pattern**
**repo:regexp-pattern@rev**
**repo:regexp-pattern rev:rev**
_alias: r_ | Include results from repos whose path matches a specified regexp-pattern. The repo path is `github.com/myteam/abc` or `code.example.com/xyz` depending on your repo host. If the regexp ends in `@rev`, search that revision instead of the default `main` branch. `repo:regexp-pattern@rev` is equivalent to `repo:regexp-pattern rev:rev` | [`repo:gorilla/mux testroute`](https://sourcegraph.com/search?q=repo:gorilla/mux+testroute)
[`repo:^github\.com/sourcegraph/sourcegraph$@v3.14.0 mux`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24%40v3.14.0+mux&patternType=keyword) | -| **-repo:regexp-pattern**
_alias: -r_ | Exclude results from repositories whose path matches the regexp | `repo:alice/ -repo:old-repo` | -| **rev:revision-pattern**
_alias: revision_ | Search a revision instead of the default branch. `rev:` can only be used in conjunction with `repo:` and may not be used more than once. See our [revision syntax](#repository-revisions) documentation to learn more | [`repo:sourcegraph/sourcegraph rev:v3.14.0 mux`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph+rev:v3.14.0+mux&patternType=keyword) | -| **file:regexp-pattern**
_alias: f_ | Only include file results whose full path matches the regexp. The regexp is unanchored by default: to match against the entire path, use regexp anchors like `^README.md$`. | [`file:\.js$ httptest`](https://sourcegraph.com/search?q=file:%5C.js%24+httptest)
[`file:internal/ httptest`](https://sourcegraph.com/search?q=file:internal/+httptest) | -| **-file:regexp-pattern**
_alias: -f_ | Exclude file results whose full path matches the regexp. The regexp is unanchored by default: to match against the entire path, use regexp anchors like `^README.md$`. | [`file:\.js$ -file:test http`](https://sourcegraph.com/search?q=file:%5C.js%24+-file:test+http) | -| **content:"pattern"** | Set the search pattern with a dedicated parameter. Useful when searching literally for a string that may conflict with the [search pattern syntax](#search-pattern-syntax). In between the quotes, the `\` character will need to be escaped (`\\` to evaluate for `\`) | [`repo:sourcegraph content:"repo:sourcegraph"`](https://sourcegraph.com/search?q=repo:sourcegraph+content:"repo:sourcegraph"&patternType=keyword) | -| **-content:"pattern"** | Exclude results from files whose content matches the pattern. | [`file:Dockerfile alpine -content:alpine:latest`](https://sourcegraph.com/search?q=file:Dockerfile+alpine+-content:alpine:latest&patternType=keyword) | -| **select:_result-type_**
**select:repo**
**select:commit.diff.added**
**select:commit.diff.removed**
**select:file**
**select:content**
**select:symbol._symbol-type_**
**select:file.owners** _(Experimental)_ | Shows only query results for a given type. For example, `select:repo` displays only distinct repository paths from search results, and `select:commit.diff.added` shows only added code matching the search. See [language definition](/code-search/queries/language#select) for full list of possible values | [`fmt.Errorf select:repo`](https://sourcegraph.com/search?q=fmt.Errorf+select:repo&patternType=keyword) | -| **language:language-name**
_alias: lang, l_ | Only include results from files in the specified programming language | [`language:typescript encoding`](https://sourcegraph.com/search?q=language:typescript+encoding) | -| **-language:language-name**
_alias: -lang, -l_ | Exclude results from files in the specified programming language | [`-language:typescript encoding`](https://sourcegraph.com/search?q=-language:typescript+encoding) | -| **type:symbol** | Perform a symbol search | [`type:symbol path`](https://sourcegraph.com/search?q=type:symbol+path) | -| **case:yes** | Perform a case sensitive query. Without this, everything is matched case insensitively | [`OPEN_FILE case:yes`](https://sourcegraph.com/search?q=OPEN_FILE+case:yes) | -| **fork:yes, fork:only** | Include results from repository forks or filter results to only repository forks. Results in repository forks are excluded by default | [`fork:yes repo:sourcegraph`](https://sourcegraph.com/search?q=fork:yes+repo:sourcegraph) | -| **archived:yes, archived:only** | The yes option, includes archived repositories. The only option, filters results to only archived repositories. Results in archived repositories are excluded by default | [`repo:sourcegraph/ archived:only`](https://sourcegraph.com/search?q=repo:%5Egithub.com/sourcegraph/+archived:only) | -| **repo:has.meta(...)** | Conditionally search inside repositories only if they are associated with a specified metadata:
1. key-value pair, or
2. key with any value, or
3. key with no value
See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | 1. `repo:has.meta(owning-team:security)`
2. `repo:has.meta(owning-team)`
3. `repo:has.meta(archived:)` | -| **repo:has.path(...)** | Conditionally search inside repositories only if they contain a file path matching the regular expression. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`repo:has.path(\.py) file:Dockerfile pip`](https://sourcegraph.com/search?q=context:global+repo:has.path%28%5C.py%29+file:Dockerfile+pip&patternType=keyword) | -| **repo:has.topic(...)** | Search only in repos repositories if they have the given GitHub or GitLab topic. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`repo:has.topic(code-search) rank`](https://sourcegraph.com/search?q=context:global+repo:sourcegraph/sourcegraph%24+rank&patternType=keyword&sm=1&groupBy=repo) | -| **repo:has.commit.after(...)** | Filter out stale repositories that don't contain commits past the specified time frame. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`repo:has.commit.after(yesterday)`](https://sourcegraph.com/search?q=context:global+repo:.*sourcegraph.*+repo:has.commit.after%28yesterday%29&patternType=keyword)
[`repo:has.commit.after(june 25 2017)`](https://sourcegraph.com/search?q=context:global+repo:.*sourcegraph.*+repo:has.commit.after%28june+25+2017%29&patternType=keyword) | -| **rev:at.time(...)** | Search a repo or a branch at a specific point in time. | [`rev:at.time(1 year ago)`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+rev:at.time%281+year+ago%29+&patternType=keyword&sm=0)
[`rev:at.time(2021-01-01)`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+rev:at.time%282021-01-01%2C+v5.0.0%29+&patternType=keyword) | -| **file:has.content(...)** | Conditionally search files only if they contain contents that match the provided regex pattern. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`file:has.content(Copyright) Sourcegraph`](https://sourcegraph.com/search?q=context:global+file:has.content%28Copyright%29+Sourcegraph&patternType=keyword) | -| **file:has.owners(...)** | Conditionally search files only if they are owned by the given owner. Empty means _any owner_. See [code ownership documentation](/code-ownership) for more | [`file:has.owner(alice@sourcegraph.com) Sourcegraph`](https://sourcegraph.com/search?q=context:global+file:has.owner%28alice@sourcegraph.com%29+Sourcegraph&patternType=keyword) | -| **file:has.contributor(...)** | Conditionally search files only if a file contributor's name or email matches the provided regex pattern. See [built-in predicates](/code-search/queries/language#built-in-file-predicate) for more | [`file:has.contributor(alice@sourcegraph.com) Sourcegraph`](https://sourcegraph.com/search?q=context:global+file:has.owner%28alice@sourcegraph.com%29+Sourcegraph&patternType=keyword) | -| **count:_N_,< /> count:all** | Retrieve N results. By default, Sourcegraph stops searching early and returns if it finds a full page of results. This is desirable for most interactive searches. To wait for all results, use **count:all** | [`count:1000 function`](https://sourcegraph.com/search?q=count:1000+repo:sourcegraph/sourcegraph$+function)
[`count:all err`](https://sourcegraph.com/search?q=repo:github.com/sourcegraph/sourcegraph+err+count:all&patternType=keyword) | -| **timeout:_go-duration-value_** | Customizes the timeout for searches. The value of the parameter is a string that can be parsed by the [Go time package's `ParseDuration`](https://golang.org/pkg/time/#ParseDuration) (e.g. 10s, 100ms). By default, the timeout is set to 10 seconds, and the search will optimize for returning results as soon as possible. The timeout value cannot be set longer than 1 minute. When provided, the search is given the full timeout to complete | [`repo:^github.com/sourcegraph timeout:15s func count:10000`](https://sourcegraph.com/search?q=repo:%5Egithub.com/sourcegraph/+timeout:15s+func+count:10000) | -| **patterntype:keyword, patterntype:regexp** | Configure your query to be interpreted as a keyword search, or a regular expression. Note: this filter is available as an accessibility option in addition to the visual toggles | [`test. patternType:keyword`](https://sourcegraph.com/search?q=test.+patternType:keyword)
[`(open/close)file patternType:regexp`](https://sourcegraph.com/search?q=%28open%7Cclose%29file&patternType=regexp) | -| **visibility:any, visibility:public, visibility:private** | Filter results to only public or private repositories. The default is to include both private and public repositories | [`type:repo visibility:public`](https://sourcegraph.com/search?q=type:repo+visibility:public) | +| **Filters** | **Description** | **Examples** | +| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| **repo:regexp-pattern**
**repo:regexp-pattern@rev**
**repo:regexp-pattern rev:rev**
_alias: r_ | Include results from repos whose path matches a specified regexp-pattern. The repo path is `github.com/myteam/abc` or `code.example.com/xyz` depending on your repo host. If the regexp ends in `@rev`, search that revision instead of the default `main` branch. `repo:regexp-pattern@rev` is equivalent to `repo:regexp-pattern rev:rev` | [`repo:gorilla/mux testroute`](https://sourcegraph.com/search?q=repo:gorilla/mux+testroute)
[`repo:^github\.com/sourcegraph/sourcegraph$@v3.14.0 mux`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24%40v3.14.0+mux&patternType=keyword) | +| **-repo:regexp-pattern**
_alias: -r_ | Exclude results from repositories whose path matches the regexp | `repo:alice/ -repo:old-repo` | +| **rev:revision-pattern**
_alias: revision_ | Search a revision instead of the default branch. `rev:` can only be used in conjunction with `repo:` and may not be used more than once. See our [revision syntax](#repository-revisions) documentation to learn more | [`repo:sourcegraph/sourcegraph rev:v3.14.0 mux`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph+rev:v3.14.0+mux&patternType=keyword) | +| **file:regexp-pattern**
_alias: f_ | Only include file results whose full path matches the regexp. The regexp is unanchored by default: to match against the entire path, use regexp anchors like `^README.md$`. | [`file:\.js$ httptest`](https://sourcegraph.com/search?q=file:%5C.js%24+httptest)
[`file:internal/ httptest`](https://sourcegraph.com/search?q=file:internal/+httptest) | +| **-file:regexp-pattern**
_alias: -f_ | Exclude file results whose full path matches the regexp. The regexp is unanchored by default: to match against the entire path, use regexp anchors like `^README.md$`. | [`file:\.js$ -file:test http`](https://sourcegraph.com/search?q=file:%5C.js%24+-file:test+http) | +| **content:"pattern"** | Set the search pattern with a dedicated parameter. Useful when searching literally for a string that may conflict with the [search pattern syntax](#search-pattern-syntax). In between the quotes, the `\` character will need to be escaped (`\\` to evaluate for `\`) | [`repo:sourcegraph content:"repo:sourcegraph"`](https://sourcegraph.com/search?q=repo:sourcegraph+content:"repo:sourcegraph"&patternType=keyword) | +| **-content:"pattern"** | Exclude results from files whose content matches the pattern. | [`file:Dockerfile alpine -content:alpine:latest`](https://sourcegraph.com/search?q=file:Dockerfile+alpine+-content:alpine:latest&patternType=keyword) | +| **select:_result-type_**
**select:repo**
**select:commit.diff.added**
**select:commit.diff.removed**
**select:file**
**select:content**
**select:symbol._symbol-type_**
**select:file.owners** _(Experimental)_ | Shows only query results for a given type. For example, `select:repo` displays only distinct repository paths from search results, and `select:commit.diff.added` shows only added code matching the search. See [language definition](/code-search/queries/language#select) for full list of possible values | [`fmt.Errorf select:repo`](https://sourcegraph.com/search?q=fmt.Errorf+select:repo&patternType=keyword) | +| **language:language-name**
_alias: lang, l_ | Only include results from files in the specified programming language | [`language:typescript encoding`](https://sourcegraph.com/search?q=language:typescript+encoding) | +| **-language:language-name**
_alias: -lang, -l_ | Exclude results from files in the specified programming language | [`-language:typescript encoding`](https://sourcegraph.com/search?q=-language:typescript+encoding) | +| **type:symbol** | Perform a symbol search | [`type:symbol path`](https://sourcegraph.com/search?q=type:symbol+path) | +| **case:yes** | Perform a case sensitive query. Without this, everything is matched case insensitively | [`OPEN_FILE case:yes`](https://sourcegraph.com/search?q=OPEN_FILE+case:yes) | +| **fork:yes, fork:only** | Include results from repository forks or filter results to only repository forks. Results in repository forks are excluded by default | [`fork:yes repo:sourcegraph`](https://sourcegraph.com/search?q=fork:yes+repo:sourcegraph) | +| **archived:yes, archived:only** | The yes option, includes archived repositories. The only option, filters results to only archived repositories. Results in archived repositories are excluded by default | [`repo:sourcegraph/ archived:only`](https://sourcegraph.com/search?q=repo:%5Egithub.com/sourcegraph/+archived:only) | +| **repo:has.meta(...)** | Conditionally search inside repositories only if they are associated with a specified metadata:
1. key-value pair, or
2. key with any value, or
3. key with no value
See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | 1. `repo:has.meta(owning-team:security)`
2. `repo:has.meta(owning-team)`
3. `repo:has.meta(archived:)` | +| **repo:has.path(...)** | Conditionally search inside repositories only if they contain a file path matching the regular expression. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`repo:has.path(\.py) file:Dockerfile pip`](https://sourcegraph.com/search?q=context:global+repo:has.path%28%5C.py%29+file:Dockerfile+pip&patternType=keyword) | +| **repo:has.topic(...)** | Search only in repos repositories if they have the given GitHub or GitLab topic. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`repo:has.topic(code-search) rank`](https://sourcegraph.com/search?q=context:global+repo:has.topic%28code-search%29+rank&patternType=keyword) | +| **repo:has.commit.after(...)** | Filter out stale repositories that don't contain commits past the specified time frame. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`repo:has.commit.after(yesterday)`](https://sourcegraph.com/search?q=context:global+repo:.*sourcegraph.*+repo:has.commit.after%28yesterday%29&patternType=keyword)
[`repo:has.commit.after(june 25 2017)`](https://sourcegraph.com/search?q=context:global+repo:.*sourcegraph.*+repo:has.commit.after%28june+25+2017%29&patternType=keyword) | +| **rev:at.time(...)** | Search a repo or a branch at a specific point in time. Requires a `repo:` filter. The optional second argument is the revision to start from. | [`repo:^github\.com/sourcegraph/zoekt$ rev:at.time(1 year ago) ctags`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/sourcegraph/zoekt%24+rev:at.time%281+year+ago%29+ctags&patternType=keyword)
[`repo:^github\.com/sourcegraph/zoekt$ rev:at.time(2024-01-01, sourcegraph-5.3) ctags`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/sourcegraph/zoekt%24+rev:at.time%282024-01-01%2C+sourcegraph-5.3%29+ctags&patternType=keyword) | +| **file:has.content(...)** | Conditionally search files only if they contain contents that match the provided regex pattern. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`file:has.content(Copyright) Sourcegraph`](https://sourcegraph.com/search?q=context:global+file:has.content%28Copyright%29+Sourcegraph&patternType=keyword) | +| **file:has.owner(...)** | Conditionally search files only if they are owned by the given owner. Empty means _any owner_. See [code ownership documentation](/code-ownership) for more | [`file:has.owner(alice@sourcegraph.com) Sourcegraph`](https://sourcegraph.com/search?q=context:global+file:has.owner%28alice@sourcegraph.com%29+Sourcegraph&patternType=keyword) | +| **file:has.contributor(...)** | Conditionally search files only if a file contributor's name or email matches the provided regex pattern. See [built-in predicates](/code-search/queries/language#built-in-file-predicate) for more | [`file:has.contributor(alice@sourcegraph.com) Sourcegraph`](https://sourcegraph.com/search?q=context:global+file:has.contributor%28alice@sourcegraph.com%29+Sourcegraph&patternType=keyword) | +| **count:_N_,< /> count:all** | Retrieve N results. By default, Sourcegraph stops searching early and returns if it finds a full page of results. This is desirable for most interactive searches. To wait for all results, use **count:all** | [`count:1000 function`](https://sourcegraph.com/search?q=count:1000+repo:sourcegraph/sourcegraph$+function)
[`count:all err`](https://sourcegraph.com/search?q=repo:github.com/sourcegraph/sourcegraph+err+count:all&patternType=keyword) | +| **timeout:_go-duration-value_** | Customizes the timeout for searches. The value of the parameter is a string that can be parsed by the [Go time package's `ParseDuration`](https://golang.org/pkg/time/#ParseDuration) (e.g. 10s, 100ms). By default, the timeout is set to 10 seconds, and the search will optimize for returning results as soon as possible. The timeout value cannot be set longer than 1 minute. When provided, the search is given the full timeout to complete | [`repo:^github.com/sourcegraph timeout:15s func count:10000`](https://sourcegraph.com/search?q=repo:%5Egithub.com/sourcegraph/+timeout:15s+func+count:10000) | +| **patterntype:keyword, patterntype:regexp** | Configure your query to be interpreted as a keyword search, or a regular expression. Note: this filter is available as an accessibility option in addition to the visual toggles | [`test. patternType:keyword`](https://sourcegraph.com/search?q=test.+patternType:keyword)
[`(open\|close)file patternType:regexp`](https://sourcegraph.com/search?q=%28open%7Cclose%29file&patternType=regexp) | +| **visibility:any, visibility:public, visibility:private** | Filter results to only public or private repositories. The default is to include both private and public repositories | [`type:repo visibility:public`](https://sourcegraph.com/search?q=type:repo+visibility:public) | Multiple or combined **repo:** and **file:** filters are intersected. For example, `repo:foo repo:bar` limits your search to repositories whose path contains **both** `foo` and `bar` (such as `github.com/alice/foobar`). To include results from repositories whose path contains **either** `foo` or `bar`, use `repo:foo|bar`. @@ -152,16 +225,16 @@ To apply the scope of the `file` filter to the entire subexpression, fully group The following filters are only used for **commit diff** and **commit message** searches, which show changes over time: -| **Filter** | **Description** | **Examples** | -| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| **repo:regexp-pattern@rev** | Specifies which Git revisions to search for commits. See our [repository revisions](#repository-revisions) documentation to learn more about the revision syntax. | [`repo:vscode@*refs/heads/:^refs/heads/master type:diff task`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/Microsoft/vscode%24%40*refs/heads/:%5Erefs/heads/master+type:diff+after:%221+month+ago%22+task#1) (unmerged commit diffs containing `task`) | -| **type:diff**
**type:commit** | Specifies the type of search. By default, searches are executed on all code at a given point in time (a branch or a commit). Specify the `type:` if you want to search over changes to code or commit messages instead (diffs or commits). | [`type:diff func`](https://sourcegraph.com/search?q=type:diff+func+repo:sourcegraph/sourcegraph$)
[`type:commit test`](https://sourcegraph.com/search?q=type:commit+test+repo:sourcegraph/sourcegraph$) | -| **author:name** | Only include results from diffs or commits authored by the user. Regexps are supported. Note that they match the whole author string of the form `Full Name `, so to include only authors from a specific domain, use `author:example.com>$`. You can also use `author:@SourcegraphUserName` to search on a Sourcegraph user's list of verified emails.

You can also search by `committer:git-email`. _Note: there is a committer only when they are a different user than the author._ | [`type:diff author:nick`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick) | -| **-author:name** | Exclude results from diffs or commits authored by the user. Regexps are supported. Note that they match the whole author string of the form `Full Name `, so to exclude authors from a specific domain, use `author:example.com>$`. You can also use `author:@SourcegraphUserName` to search on a Sourcegraph user's list of verified emails.

You can also search by `committer:git-email`. _Note: there is a committer only when they are a different user than the author._ | [`type:diff author:nick`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick) | -| **before:"string specifying time frame"** | Only include results from diffs or commits which have a commit date before the specified time frame | [`before:"last thursday"`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick+before:%22last+thursday%22)
[`before:"november 1 2019"`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick+before:%22november+1+2019%22) | -| **after:"string specifying time frame"** | Only include results from diffs or commits which have a commit date after the specified time frame | [`after:"6 weeks ago"`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick+after:%226+weeks+ago%22)
[`after:"november 1 2019"`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick+after:%22november+1+2019%22) | -| **message:"any string"** | Only include results from diffs or commits which have commit messages containing the string | [`type:commit message:"testing"`](https://sourcegraph.com/search?q=type:commit+repo:sourcegraph/sourcegraph$+message:%22testing%22)
[`type:diff message:"testing"`](https://sourcegraph.com/search?q=type:diff+repo:sourcegraph/sourcegraph$+message:%22testing%22) | -| **-message:"any string"** | Exclude the results from diffs or commits which have commit messages containing the string | [`type:commit message:"testing"`](https://sourcegraph.com/search?q=type:commit+repo:sourcegraph/sourcegraph$+message:%22testing%22)
[`type:diff message:"testing"`](https://sourcegraph.com/search?q=type:diff+repo:sourcegraph/sourcegraph$+message:%22testing%22) | +| **Filter** | **Description** | **Examples** | +| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| **repo:regexp-pattern@rev** | Specifies which Git revisions to search for commits. See our [repository revisions](#repository-revisions) documentation to learn more about the revision syntax. | [`repo:vscode@*refs/heads/:^refs/heads/main type:diff task`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/microsoft/vscode%24%40*refs/heads/:%5Erefs/heads/main+type:diff+after:%221+month+ago%22+task) (unmerged commit diffs containing `task`) | +| **type:diff**
**type:commit** | Specifies the type of search. By default, searches are executed on all code at a given point in time (a branch or a commit). Specify the `type:` if you want to search over changes to code or commit messages instead (diffs or commits). | [`type:diff func`](https://sourcegraph.com/search?q=type:diff+func+repo:sourcegraph/sourcegraph$)
[`type:commit test`](https://sourcegraph.com/search?q=type:commit+test+repo:sourcegraph/sourcegraph$) | +| **author:name** | Only include results from diffs or commits authored by the user. Regexps are supported. Note that they match the whole author string of the form `Full Name `, so to include only authors from a specific domain, use `author:example.com>$`. You can also use `author:@SourcegraphUserName` to search on a Sourcegraph user's list of verified emails.

You can also search by `committer:git-email`. _Note: there is a committer only when they are a different user than the author._ | [`type:diff author:nick`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick) | +| **-author:name** | Exclude results from diffs or commits authored by the user. Regexps are supported. Note that they match the whole author string of the form `Full Name `, so to exclude authors from a specific domain, use `author:example.com>$`. You can also use `author:@SourcegraphUserName` to search on a Sourcegraph user's list of verified emails.

You can also search by `committer:git-email`. _Note: there is a committer only when they are a different user than the author._ | [`type:diff author:nick`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick) | +| **before:"string specifying time frame"** | Only include results from diffs or commits which have a commit date before the specified time frame | [`type:diff before:"last thursday"`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick+before:%22last+thursday%22)
[`type:diff before:"november 1 2019"`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick+before:%22november+1+2019%22) | +| **after:"string specifying time frame"** | Only include results from diffs or commits which have a commit date after the specified time frame | [`type:diff after:"6 weeks ago"`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick+after:%226+weeks+ago%22)
[`type:diff after:"november 1 2019"`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick+after:%22november+1+2019%22) | +| **message:"any string"** | Only include results from diffs or commits which have commit messages containing the string | [`type:commit message:"testing"`](https://sourcegraph.com/search?q=type:commit+repo:sourcegraph/sourcegraph$+message:%22testing%22)
[`type:diff message:"testing"`](https://sourcegraph.com/search?q=type:diff+repo:sourcegraph/sourcegraph$+message:%22testing%22) | +| **-message:"any string"** | Exclude the results from diffs or commits which have commit messages containing the string | [`type:commit message:"testing"`](https://sourcegraph.com/search?q=type:commit+repo:sourcegraph/sourcegraph$+message:%22testing%22)
[`type:diff message:"testing"`](https://sourcegraph.com/search?q=type:diff+repo:sourcegraph/sourcegraph$+message:%22testing%22) | ## Repository Search @@ -188,8 +261,8 @@ with `3.18`, but not a branch called `3.18` and vice versa for `@refs/heads/3.18 **Glob patterns** allow you to search over a range of branches or tags. Prepend `*` to mark a revision as glob pattern and add the glob-pattern after it like this `repo:@*`. For example: -- [`@*refs/heads/*`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/docker/machine%24%40*refs/heads/*+middleware&patternType=keyword) - search across all branches -- [`@*refs/tags/*`](https://sourcegraph.com/search?q=repo:github.com/docker/machine%24%40*refs/tags/*+server&patternType=keyword) - search across all tags +- [`@*refs/heads/*`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/zoekt%24%40*refs/heads/*+ctags&patternType=keyword) - search across all branches +- [`@*refs/tags/*`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/src-cli%24%40*refs/tags/*+SRC_ENDPOINT&patternType=keyword) - search across all tags We automatically add a trailing `/*` if it is missing from the glob pattern. diff --git a/docs/code-search/types/search-jobs.mdx b/docs/code-search/types/search-jobs.mdx index 03bfa86c9..ef281aa2f 100644 --- a/docs/code-search/types/search-jobs.mdx +++ b/docs/code-search/types/search-jobs.mdx @@ -72,7 +72,7 @@ The following elements of our query language are not supported: ### How can I run a search job against all branches and all repositories? You can use a combination of the `repo:` and `rev:` filter to search across all branches and repositories. -For example, `r: rev:*/refs/heads/* foo` will search for `foo` across all branches and all repositories. +For example, `repo:.* rev:*refs/heads/* foo` searches for `foo` across all branches of all repositories. See the [search syntax documentation](/code-search/queries#repository-revisions) for more details. ### Is there a time limit for a search job? From 54269dfca14a4c09cf414070a38a04561f2d0f67 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:54:29 +0000 Subject: [PATCH 2/5] Use public repositories in search query examples Replace examples that searched private repositories, placeholders, or repositories that are no longer on Sourcegraph.com with queries against kubernetes/kubernetes and microsoft/vscode, so every linked example runs on Sourcegraph.com and shows the query it links to. Amp-Thread-ID: https://ampcode.com/threads/T-1f043295-17f3-4f30-b014-ca3aff6606c2 Co-authored-by: Amp --- cspell-allow-list.txt | 1 + docs/code-search/queries/index.mdx | 232 ++++++++++++++--------------- 2 files changed, 113 insertions(+), 120 deletions(-) diff --git a/cspell-allow-list.txt b/cspell-allow-list.txt index 2177b4e74..a0532ab32 100644 --- a/cspell-allow-list.txt +++ b/cspell-allow-list.txt @@ -292,6 +292,7 @@ keymappings keypair killall Kitts +klog kubeconfig kubelet kustomization diff --git a/docs/code-search/queries/index.mdx b/docs/code-search/queries/index.mdx index 9586500d2..02fe151ea 100644 --- a/docs/code-search/queries/index.mdx +++ b/docs/code-search/queries/index.mdx @@ -12,72 +12,64 @@ For a graphical view of Sourcegraph's query syntax, see the [search language ref Most queries combine up to four parts: -1. **Scope**: choose the repositories to search, for example `repo:my-org/payments`. -2. **Narrow**: filter by language, file path, or result type, for example `lang:go -file:test`. -3. **Version**: choose a branch, tag, or commit, for example `rev:develop`. -4. **Find**: describe what to match, for example `"deprecatedAPI"`. +1. **Scope**: choose the repositories to search, for example `repo:^github\.com/kubernetes/kubernetes$`. +2. **Narrow**: filter by language, file path, or result type, for example `lang:go -file:_test\.go$`. +3. **Version**: choose a branch, tag, or commit, for example `rev:release-1.33`. +4. **Find**: describe what to match, for example `"feature gate"`. -```sgquery -repo:my-org/payments lang:go -file:test rev:develop "deprecatedAPI" -``` +[`repo:^github\.com/kubernetes/kubernetes$ lang:go -file:_test\.go$ rev:release-1.33 "feature gate"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+lang:go+-file:_test%5C.go%24+rev:release-1.33+%22feature+gate%22&patternType=keyword) -In these examples, replace `my-org`, `my-repo`, `payments`, and the branch and tag names with names from your Sourcegraph instance. +The examples on this page search public repositories on Sourcegraph.com, mostly [kubernetes/kubernetes](https://github.com/kubernetes/kubernetes) and [microsoft/vscode](https://github.com/microsoft/vscode). To search your own code, change the `repo:` filter. ### Find code -| To find | Query | -| ------------------------------------------ | ----------------------------------------------- | -| Files that contain all terms, in any order | `authentication middleware` | -| An exact phrase | `"authentication failed"` | -| A regular expression | `/auth.*failed/` | -| A combination of terms | `(error OR exception) AND retry NOT deprecated` | -| Text in exactly this case | `APIKey case:yes` | +| To find | Query | +| ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Files that contain all terms, in any order | [`repo:^github\.com/kubernetes/kubernetes$ kubelet eviction`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+kubelet+eviction&patternType=keyword) | +| An exact phrase | [`repo:^github\.com/kubernetes/kubernetes$ "failed to sync pod"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%22failed+to+sync+pod%22&patternType=keyword) | +| A regular expression | [`repo:^github\.com/kubernetes/kubernetes$ /eviction.*threshold/`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+/eviction.*threshold/&patternType=keyword) | +| A combination of terms | [`repo:^github\.com/kubernetes/kubernetes$ (error OR warning) AND retry NOT deprecated`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%28error+OR+warning%29+AND+retry+NOT+deprecated&patternType=keyword) | +| Text in exactly this case | [`repo:^github\.com/kubernetes/kubernetes$ PodSpec case:yes`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+PodSpec+case:yes&patternType=keyword) | ### Narrow the search -| To search | Query | -| ---------------------------------------------- | ---------------------------------------- | -| One repository | `repo:^github\.com/my-org/my-repo$` | -| Repositories that match a pattern, except some | `repo:my-org/ -repo:legacy` | -| Files in repositories that contain a path | `repo:has.path(\.py) file:Dockerfile` | -| Repositories with recent commits | `repo:has.commit.after(1 month ago)` | -| One language | `lang:typescript` | -| All languages except one | `"authentication failed" -lang:markdown` | -| Symbol definitions | `type:symbol UserService` | -| Files with an extension that contain a pattern | `file:\.py$ file:has.content(TODO)` | +| To search | Query | +| ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| One repository | [`repo:^github\.com/kubernetes/kubernetes$`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24&patternType=keyword) | +| Repositories that match a pattern, except some | [`repo:^github\.com/kubernetes/ -repo:kubernetes/website`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+-repo:kubernetes/website&patternType=keyword) | +| Files in repositories that contain a path | [`repo:^github\.com/kubernetes/ repo:has.path(\.py) file:Dockerfile`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.path%28%5C.py%29+file:Dockerfile&patternType=keyword) | +| Repositories with recent commits | [`repo:^github\.com/kubernetes/ repo:has.commit.after(1 month ago)`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.commit.after%281+month+ago%29&patternType=keyword) | +| One language | [`repo:^github\.com/microsoft/vscode$ lang:typescript registerCommand`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/microsoft/vscode%24+lang:typescript+registerCommand&patternType=keyword) | +| All languages except one | [`repo:^github\.com/kubernetes/kubernetes$ "feature gate" -lang:markdown`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%22feature+gate%22+-lang:markdown&patternType=keyword) | +| Symbol definitions | [`repo:^github\.com/kubernetes/kubernetes$ type:symbol NewKubeletCommand`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:symbol+NewKubeletCommand&patternType=keyword) | +| Files with an extension that contain a pattern | [`repo:^github\.com/kubernetes/kubernetes$ file:\.go$ file:has.content(TODO)`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:%5C.go%24+file:has.content%28TODO%29&patternType=keyword) | -`repo:` and `file:` take regular expressions, so `repo:my-org/my-repo` also matches `my-org/my-repo-legacy`. Use `^` and `$` to match one repository. The argument of `file:has.content(...)` is also a regular expression, and quotes in it are matched literally: `file:has.content("TODO")` matches only files that contain `"TODO"` with the quotes. +`repo:` and `file:` take regular expressions, so `repo:kubernetes/kubernetes` also matches `kubernetes/kubernetes-template-project`. Use `^` and `$` to match one repository. The argument of `file:has.content(...)` is also a regular expression, and quotes in it are matched literally: `file:has.content("TODO")` matches only files that contain `"TODO"` with the quotes. -Sourcegraph combines filters with `AND`, so you don't need an operator between them. For example, to find `authentication failed` in Node.js repositories, excluding generated and vendored code: +Sourcegraph combines filters with `AND`, so you don't need an operator between them. For example, to find `authentication failed` in Node.js repositories in the `microsoft` organization, excluding generated and vendored code: -```sgquery -repo:has.path(package.json) -file:(generated|vendor|dist|node_modules) "authentication failed" -``` +[`repo:^github\.com/microsoft/ repo:has.path(package.json) -file:(generated|vendor|dist|node_modules) "authentication failed"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/microsoft/+repo:has.path%28package.json%29+-file:%28generated%7Cvendor%7Cdist%7Cnode_modules%29+%22authentication+failed%22&patternType=keyword) -To list recently active Go repositories that contain a Dockerfile: +To list recently active Go repositories in the `kubernetes` organization that contain a Dockerfile: -```sgquery -repo:has.path(Dockerfile) repo:has.commit.after(3 months ago) lang:go select:repo -``` +[`repo:^github\.com/kubernetes/ repo:has.path(Dockerfile) repo:has.commit.after(3 months ago) lang:go select:repo`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.path%28Dockerfile%29+repo:has.commit.after%283+months+ago%29+lang:go+select:repo&patternType=keyword) ### Search branches and tags -Sourcegraph searches each repository's default branch unless the query has a `rev:` filter. A `rev:` filter needs a `repo:` filter in the same query. On its own, a query such as `rev:develop` returns an `Invalid syntax` alert that asks for a `repo:` filter. +Sourcegraph searches each repository's default branch unless the query has a `rev:` filter. A `rev:` filter needs a `repo:` filter in the same query. On its own, a query such as `rev:release-1.33` returns an `Invalid syntax` alert that asks for a `repo:` filter. -| To search | Query | -| ------------------------ | --------------------------------------- | -| A branch, tag, or commit | `repo:my-org/my-repo rev:release-1.0` | -| The default branch | `repo:my-org/my-repo rev:HEAD` | -| All branches | `repo:my-org/my-repo rev:*refs/heads/*` | -| All tags | `repo:my-org/my-repo rev:*refs/tags/*` | +| To search | Query | +| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| A branch, tag, or commit | [`repo:^github\.com/kubernetes/kubernetes$ rev:release-1.33 kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:release-1.33+kubelet&patternType=keyword) | +| The default branch | [`repo:^github\.com/kubernetes/kubernetes$ rev:HEAD kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:HEAD+kubelet&patternType=keyword) | +| All branches | [`repo:^github\.com/kubernetes/kubernetes$ rev:*refs/heads/* kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:*refs/heads/*+kubelet&patternType=keyword) | +| All tags | [`repo:^github\.com/kubernetes/kubernetes$ rev:*refs/tags/* kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:*refs/tags/*+kubelet&patternType=keyword) | -For example, to find `authentication` on every branch of the repositories that match `payments`: +If some repositories that match `repo:` don't have the revision, Sourcegraph searches the others and lists the missing revisions under **Some revisions could not be searched**. For example, most repositories in the `kubernetes` organization don't have a `release-1.33` branch: -```sgquery -repo:payments rev:*refs/heads/* authentication -``` +[`repo:^github\.com/kubernetes/ rev:release-1.33 kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+rev:release-1.33+kubelet&patternType=keyword) -If some repositories that match `repo:` don't have the revision, Sourcegraph searches the others and lists the missing revisions under **Some revisions could not be searched**. To search several revisions at once, exclude branches, or use commit hashes, see [repository revisions](#repository-revisions). +To search several revisions at once, exclude branches, or use commit hashes, see [repository revisions](#repository-revisions). ### Saved scopes and large searches @@ -92,13 +84,13 @@ This section documents the search pattern syntax in Sourcegraph. To match file c Keyword search matches individual terms anywhere in the document or the filename. Use `"..."` to match phrases exactly. Specify regular expressions inside `/.../`. -| Search pattern syntax | Description | -| ----------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | -| [`foo bar`](https://sourcegraph.com/search?q=foo+bar&patternType=keyword) | Match documents containing both `foo` and `bar` anywhere in the document. | -| [`"foo bar"`](https://sourcegraph.com/search?q=%22foo+bar%22&patternType=keyword) | Match the string `foo bar` exactly. The space between the terms is interpreted literally. The quotes are not matched. | -| [`"foo \"bar\""`](https://sourcegraph.com/search?q=context:global+%22foo+%5C%22bar%5C%22%22&patternType=keyword) | Match the string `foo "bar"` exactly. | -| [`/foo.*bar/`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+/foo.*bar/&patternType=keyword) | Match the **regular expression** `foo.*bar`. We support [RE2 syntax](https://golang.org/s/re2syntax). | -| [`foo OR bar`](https://sourcegraph.com/search?q=context:global+foo+OR+bar&patternType=keyword) | Match documents containing `foo` _or_ `bar` anywhere in the document. | +| Search pattern syntax | Description | +| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | +| [`repo:^github\.com/kubernetes/kubernetes$ foo bar`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+foo+bar&patternType=keyword) | Match documents containing both `foo` and `bar` anywhere in the document. | +| [`repo:^github\.com/kubernetes/kubernetes$ "foo bar"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%22foo+bar%22&patternType=keyword) | Match the string `foo bar` exactly. The space between the terms is interpreted literally. The quotes are not matched. | +| [`repo:^github\.com/kubernetes/kubernetes$ "foo \"bar\""`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%22foo+%5C%22bar%5C%22%22&patternType=keyword) | Match the string `foo "bar"` exactly. | +| [`repo:^github\.com/kubernetes/kubernetes$ /foo.*bar/`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+/foo.*bar/&patternType=keyword) | Match the **regular expression** `foo.*bar`. We support [RE2 syntax](https://golang.org/s/re2syntax). | +| [`repo:^github\.com/kubernetes/kubernetes$ foo OR bar`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+foo+OR+bar&patternType=keyword) | Match documents containing `foo` _or_ `bar` anywhere in the document. | Matching is case-insensitive by default (toggle the `Aa` button to change). @@ -120,12 +112,12 @@ Clicking the (.\*) toggle interprets all search patterns as regular expressions. mean **match anything**. Patterns inside quotes mean **match exactly**. -| **Search Syntax** | **Description** | -| ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- | -| [`foo bar`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+foo+bar&patternType=regexp) | Search for the regexp `foo(.*?)bar`. Spaces between non-whitespace strings becomes `.*?` to create a fuzzy search | -| [`foo\ bar`](https://sourcegraph.com/search?q=foo%5C+bar&patternType=regexp) or [`/foo bar/`](https://sourcegraph.com/search?q=/foo+bar/&patternType=regexp) | Search for the regexp `foo bar`. The `\` escapes the space and treats the space as part of the pattern. Use `/.../` to avoid escaping spaces | -| [`foo\nbar`](https://sourcegraph.com/search?q=foo%5Cnbar&patternType=regexp) | Perform a multiline regexp search. `\n` is interpreted as a newline | -| [`"foo bar"`](https://sourcegraph.com/search?q=%22foo+bar%22&patternType=regexp) | Match the string `foo bar` exactly. The space between the terms is interpreted literally. The quotes are not matched. | +| **Search Syntax** | **Description** | +| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | +| [`repo:^github\.com/kubernetes/kubernetes$ foo bar`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+foo+bar&patternType=regexp) | Search for the regexp `foo(.*?)bar`. Spaces between non-whitespace strings becomes `.*?` to create a fuzzy search | +| [`repo:^github\.com/kubernetes/kubernetes$ foo\ bar`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+foo%5C+bar&patternType=regexp) or [`repo:^github\.com/kubernetes/kubernetes$ /foo bar/`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+/foo+bar/&patternType=regexp) | Search for the regexp `foo bar`. The `\` escapes the space and treats the space as part of the pattern. Use `/.../` to avoid escaping spaces | +| [`repo:^github\.com/kubernetes/kubernetes$ foo\nbar`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+foo%5Cnbar&patternType=regexp) | Perform a multiline regexp search. `\n` is interpreted as a newline | +| [`repo:^github\.com/kubernetes/kubernetes$ "foo bar"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%22foo+bar%22&patternType=regexp) | Match the string `foo bar` exactly. The space between the terms is interpreted literally. The quotes are not matched. | We support [RE2 syntax](https://golang.org/s/re2syntax). Matching is @@ -136,56 +128,56 @@ Clicking the (.\*) toggle interprets all search patterns as regular expressions. The following filters can be used on all searches (using [RE2 syntax](https://golang.org/s/re2syntax) any place a regex is accepted): -| **Filters** | **Description** | **Examples** | -| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| **repo:regexp-pattern**
**repo:regexp-pattern@rev**
**repo:regexp-pattern rev:rev**
_alias: r_ | Include results from repos whose path matches a specified regexp-pattern. The repo path is `github.com/myteam/abc` or `code.example.com/xyz` depending on your repo host. If the regexp ends in `@rev`, search that revision instead of the default `main` branch. `repo:regexp-pattern@rev` is equivalent to `repo:regexp-pattern rev:rev` | [`repo:gorilla/mux testroute`](https://sourcegraph.com/search?q=repo:gorilla/mux+testroute)
[`repo:^github\.com/sourcegraph/sourcegraph$@v3.14.0 mux`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24%40v3.14.0+mux&patternType=keyword) | -| **-repo:regexp-pattern**
_alias: -r_ | Exclude results from repositories whose path matches the regexp | `repo:alice/ -repo:old-repo` | -| **rev:revision-pattern**
_alias: revision_ | Search a revision instead of the default branch. `rev:` can only be used in conjunction with `repo:` and may not be used more than once. See our [revision syntax](#repository-revisions) documentation to learn more | [`repo:sourcegraph/sourcegraph rev:v3.14.0 mux`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph+rev:v3.14.0+mux&patternType=keyword) | -| **file:regexp-pattern**
_alias: f_ | Only include file results whose full path matches the regexp. The regexp is unanchored by default: to match against the entire path, use regexp anchors like `^README.md$`. | [`file:\.js$ httptest`](https://sourcegraph.com/search?q=file:%5C.js%24+httptest)
[`file:internal/ httptest`](https://sourcegraph.com/search?q=file:internal/+httptest) | -| **-file:regexp-pattern**
_alias: -f_ | Exclude file results whose full path matches the regexp. The regexp is unanchored by default: to match against the entire path, use regexp anchors like `^README.md$`. | [`file:\.js$ -file:test http`](https://sourcegraph.com/search?q=file:%5C.js%24+-file:test+http) | -| **content:"pattern"** | Set the search pattern with a dedicated parameter. Useful when searching literally for a string that may conflict with the [search pattern syntax](#search-pattern-syntax). In between the quotes, the `\` character will need to be escaped (`\\` to evaluate for `\`) | [`repo:sourcegraph content:"repo:sourcegraph"`](https://sourcegraph.com/search?q=repo:sourcegraph+content:"repo:sourcegraph"&patternType=keyword) | -| **-content:"pattern"** | Exclude results from files whose content matches the pattern. | [`file:Dockerfile alpine -content:alpine:latest`](https://sourcegraph.com/search?q=file:Dockerfile+alpine+-content:alpine:latest&patternType=keyword) | -| **select:_result-type_**
**select:repo**
**select:commit.diff.added**
**select:commit.diff.removed**
**select:file**
**select:content**
**select:symbol._symbol-type_**
**select:file.owners** _(Experimental)_ | Shows only query results for a given type. For example, `select:repo` displays only distinct repository paths from search results, and `select:commit.diff.added` shows only added code matching the search. See [language definition](/code-search/queries/language#select) for full list of possible values | [`fmt.Errorf select:repo`](https://sourcegraph.com/search?q=fmt.Errorf+select:repo&patternType=keyword) | -| **language:language-name**
_alias: lang, l_ | Only include results from files in the specified programming language | [`language:typescript encoding`](https://sourcegraph.com/search?q=language:typescript+encoding) | -| **-language:language-name**
_alias: -lang, -l_ | Exclude results from files in the specified programming language | [`-language:typescript encoding`](https://sourcegraph.com/search?q=-language:typescript+encoding) | -| **type:symbol** | Perform a symbol search | [`type:symbol path`](https://sourcegraph.com/search?q=type:symbol+path) | -| **case:yes** | Perform a case sensitive query. Without this, everything is matched case insensitively | [`OPEN_FILE case:yes`](https://sourcegraph.com/search?q=OPEN_FILE+case:yes) | -| **fork:yes, fork:only** | Include results from repository forks or filter results to only repository forks. Results in repository forks are excluded by default | [`fork:yes repo:sourcegraph`](https://sourcegraph.com/search?q=fork:yes+repo:sourcegraph) | -| **archived:yes, archived:only** | The yes option, includes archived repositories. The only option, filters results to only archived repositories. Results in archived repositories are excluded by default | [`repo:sourcegraph/ archived:only`](https://sourcegraph.com/search?q=repo:%5Egithub.com/sourcegraph/+archived:only) | -| **repo:has.meta(...)** | Conditionally search inside repositories only if they are associated with a specified metadata:
1. key-value pair, or
2. key with any value, or
3. key with no value
See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | 1. `repo:has.meta(owning-team:security)`
2. `repo:has.meta(owning-team)`
3. `repo:has.meta(archived:)` | -| **repo:has.path(...)** | Conditionally search inside repositories only if they contain a file path matching the regular expression. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`repo:has.path(\.py) file:Dockerfile pip`](https://sourcegraph.com/search?q=context:global+repo:has.path%28%5C.py%29+file:Dockerfile+pip&patternType=keyword) | -| **repo:has.topic(...)** | Search only in repos repositories if they have the given GitHub or GitLab topic. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`repo:has.topic(code-search) rank`](https://sourcegraph.com/search?q=context:global+repo:has.topic%28code-search%29+rank&patternType=keyword) | -| **repo:has.commit.after(...)** | Filter out stale repositories that don't contain commits past the specified time frame. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`repo:has.commit.after(yesterday)`](https://sourcegraph.com/search?q=context:global+repo:.*sourcegraph.*+repo:has.commit.after%28yesterday%29&patternType=keyword)
[`repo:has.commit.after(june 25 2017)`](https://sourcegraph.com/search?q=context:global+repo:.*sourcegraph.*+repo:has.commit.after%28june+25+2017%29&patternType=keyword) | -| **rev:at.time(...)** | Search a repo or a branch at a specific point in time. Requires a `repo:` filter. The optional second argument is the revision to start from. | [`repo:^github\.com/sourcegraph/zoekt$ rev:at.time(1 year ago) ctags`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/sourcegraph/zoekt%24+rev:at.time%281+year+ago%29+ctags&patternType=keyword)
[`repo:^github\.com/sourcegraph/zoekt$ rev:at.time(2024-01-01, sourcegraph-5.3) ctags`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/sourcegraph/zoekt%24+rev:at.time%282024-01-01%2C+sourcegraph-5.3%29+ctags&patternType=keyword) | -| **file:has.content(...)** | Conditionally search files only if they contain contents that match the provided regex pattern. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`file:has.content(Copyright) Sourcegraph`](https://sourcegraph.com/search?q=context:global+file:has.content%28Copyright%29+Sourcegraph&patternType=keyword) | -| **file:has.owner(...)** | Conditionally search files only if they are owned by the given owner. Empty means _any owner_. See [code ownership documentation](/code-ownership) for more | [`file:has.owner(alice@sourcegraph.com) Sourcegraph`](https://sourcegraph.com/search?q=context:global+file:has.owner%28alice@sourcegraph.com%29+Sourcegraph&patternType=keyword) | -| **file:has.contributor(...)** | Conditionally search files only if a file contributor's name or email matches the provided regex pattern. See [built-in predicates](/code-search/queries/language#built-in-file-predicate) for more | [`file:has.contributor(alice@sourcegraph.com) Sourcegraph`](https://sourcegraph.com/search?q=context:global+file:has.contributor%28alice@sourcegraph.com%29+Sourcegraph&patternType=keyword) | -| **count:_N_,< /> count:all** | Retrieve N results. By default, Sourcegraph stops searching early and returns if it finds a full page of results. This is desirable for most interactive searches. To wait for all results, use **count:all** | [`count:1000 function`](https://sourcegraph.com/search?q=count:1000+repo:sourcegraph/sourcegraph$+function)
[`count:all err`](https://sourcegraph.com/search?q=repo:github.com/sourcegraph/sourcegraph+err+count:all&patternType=keyword) | -| **timeout:_go-duration-value_** | Customizes the timeout for searches. The value of the parameter is a string that can be parsed by the [Go time package's `ParseDuration`](https://golang.org/pkg/time/#ParseDuration) (e.g. 10s, 100ms). By default, the timeout is set to 10 seconds, and the search will optimize for returning results as soon as possible. The timeout value cannot be set longer than 1 minute. When provided, the search is given the full timeout to complete | [`repo:^github.com/sourcegraph timeout:15s func count:10000`](https://sourcegraph.com/search?q=repo:%5Egithub.com/sourcegraph/+timeout:15s+func+count:10000) | -| **patterntype:keyword, patterntype:regexp** | Configure your query to be interpreted as a keyword search, or a regular expression. Note: this filter is available as an accessibility option in addition to the visual toggles | [`test. patternType:keyword`](https://sourcegraph.com/search?q=test.+patternType:keyword)
[`(open\|close)file patternType:regexp`](https://sourcegraph.com/search?q=%28open%7Cclose%29file&patternType=regexp) | -| **visibility:any, visibility:public, visibility:private** | Filter results to only public or private repositories. The default is to include both private and public repositories | [`type:repo visibility:public`](https://sourcegraph.com/search?q=type:repo+visibility:public) | - -Multiple or combined **repo:** and **file:** filters are intersected. For example, `repo:foo repo:bar` limits your search to repositories whose path contains **both** `foo` and `bar` (such as `github.com/alice/foobar`). To include results from repositories whose path contains **either** `foo` or `bar`, use `repo:foo|bar`. +| **Filters** | **Description** | **Examples** | +| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| **repo:regexp-pattern**
**repo:regexp-pattern@rev**
**repo:regexp-pattern rev:rev**
_alias: r_ | Include results from repos whose path matches a specified regexp-pattern. The repo path is `github.com/kubernetes/kubernetes` or `code.example.com/xyz` depending on your repo host. If the regexp ends in `@rev`, search that revision instead of the default `main` branch. `repo:regexp-pattern@rev` is equivalent to `repo:regexp-pattern rev:rev` | [`repo:^github\.com/kubernetes/kubernetes$ kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+kubelet&patternType=keyword)
[`repo:^github\.com/kubernetes/kubernetes$@v1.31.0 kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24@v1.31.0+kubelet&patternType=keyword) | +| **-repo:regexp-pattern**
_alias: -r_ | Exclude results from repositories whose path matches the regexp | [`repo:^github\.com/kubernetes/ -repo:kubernetes/website kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+-repo:kubernetes/website+kubelet&patternType=keyword) | +| **rev:revision-pattern**
_alias: revision_ | Search a revision instead of the default branch. `rev:` can only be used in conjunction with `repo:` and may not be used more than once. See our [revision syntax](#repository-revisions) documentation to learn more | [`repo:^github\.com/kubernetes/kubernetes$ rev:v1.31.0 kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:v1.31.0+kubelet&patternType=keyword) | +| **file:regexp-pattern**
_alias: f_ | Only include file results whose full path matches the regexp. The regexp is unanchored by default: to match against the entire path, use regexp anchors like `^README.md$`. | [`repo:^github\.com/kubernetes/kubernetes$ file:\.sh$ kubectl`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:%5C.sh%24+kubectl&patternType=keyword)
[`repo:^github\.com/kubernetes/kubernetes$ file:pkg/kubelet/ httptest`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:pkg/kubelet/+httptest&patternType=keyword) | +| **-file:regexp-pattern**
_alias: -f_ | Exclude file results whose full path matches the regexp. The regexp is unanchored by default: to match against the entire path, use regexp anchors like `^README.md$`. | [`repo:^github\.com/kubernetes/kubernetes$ file:\.go$ -file:_test\.go$ httptest`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:%5C.go%24+-file:_test%5C.go%24+httptest&patternType=keyword) | +| **content:"pattern"** | Set the search pattern with a dedicated parameter. Useful when searching literally for a string that may conflict with the [search pattern syntax](#search-pattern-syntax). In between the quotes, the `\` character will need to be escaped (`\\` to evaluate for `\`) | [`repo:^github\.com/kubernetes/kubernetes$ content:"repo:"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+content:%22repo:%22&patternType=keyword) | +| **-content:"pattern"** | Exclude results from files whose content matches the pattern. | [`repo:^github\.com/kubernetes/kubernetes$ file:Dockerfile FROM -content:golang`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:Dockerfile+FROM+-content:golang&patternType=keyword) | +| **select:_result-type_**
**select:repo**
**select:commit.diff.added**
**select:commit.diff.removed**
**select:file**
**select:content**
**select:symbol._symbol-type_**
**select:file.owners** _(Experimental)_ | Shows only query results for a given type. For example, `select:repo` displays only distinct repository paths from search results, and `select:commit.diff.added` shows only added code matching the search. See [language definition](/code-search/queries/language#select) for full list of possible values | [`repo:^github\.com/kubernetes/ fmt.Errorf select:repo`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+fmt.Errorf+select:repo&patternType=keyword) | +| **language:language-name**
_alias: lang, l_ | Only include results from files in the specified programming language | [`repo:^github\.com/microsoft/vscode$ language:typescript encoding`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/microsoft/vscode%24+language:typescript+encoding&patternType=keyword) | +| **-language:language-name**
_alias: -lang, -l_ | Exclude results from files in the specified programming language | [`repo:^github\.com/microsoft/vscode$ -language:typescript encoding`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/microsoft/vscode%24+-language:typescript+encoding&patternType=keyword) | +| **type:symbol** | Perform a symbol search | [`repo:^github\.com/kubernetes/kubernetes$ type:symbol path`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:symbol+path&patternType=keyword) | +| **case:yes** | Perform a case sensitive query. Without this, everything is matched case insensitively | [`repo:^github\.com/kubernetes/kubernetes$ KUBECONFIG case:yes`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+KUBECONFIG+case:yes&patternType=keyword) | +| **fork:yes, fork:only** | Include results from repository forks or filter results to only repository forks. Results in repository forks are excluded by default | [`fork:yes repo:qemu`](https://sourcegraph.com/search?q=fork:yes+repo:qemu&patternType=keyword) | +| **archived:yes, archived:only** | The yes option, includes archived repositories. The only option, filters results to only archived repositories. Results in archived repositories are excluded by default | [`repo:^github\.com/kubernetes/ archived:only`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+archived:only&patternType=keyword) | +| **repo:has.meta(...)** | Conditionally search inside repositories only if they are associated with a specified metadata:
1. key-value pair, or
2. key with any value, or
3. key with no value
See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | 1. `repo:has.meta(owning-team:security)`
2. `repo:has.meta(owning-team)`
3. `repo:has.meta(archived:)` | +| **repo:has.path(...)** | Conditionally search inside repositories only if they contain a file path matching the regular expression. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`repo:^github\.com/kubernetes/ repo:has.path(\.py) file:Dockerfile pip`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.path%28%5C.py%29+file:Dockerfile+pip&patternType=keyword) | +| **repo:has.topic(...)** | Search only in repos repositories if they have the given GitHub or GitLab topic. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`repo:has.topic(kubernetes) kubelet`](https://sourcegraph.com/search?q=repo:has.topic%28kubernetes%29+kubelet&patternType=keyword) | +| **repo:has.commit.after(...)** | Filter out stale repositories that don't contain commits past the specified time frame. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`repo:^github\.com/kubernetes/ repo:has.commit.after(yesterday)`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.commit.after%28yesterday%29&patternType=keyword)
[`repo:^github\.com/kubernetes/ repo:has.commit.after(june 25 2017)`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.commit.after%28june+25+2017%29&patternType=keyword) | +| **rev:at.time(...)** | Search a repo or a branch at a specific point in time. Requires a `repo:` filter. The optional second argument is the revision to start from. | [`repo:^github\.com/kubernetes/kubernetes$ rev:at.time(1 year ago) kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:at.time%281+year+ago%29+kubelet&patternType=keyword)
[`repo:^github\.com/kubernetes/kubernetes$ rev:at.time(2024-01-01, release-1.29) kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:at.time%282024-01-01,+release-1.29%29+kubelet&patternType=keyword) | +| **file:has.content(...)** | Conditionally search files only if they contain contents that match the provided regex pattern. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`repo:^github\.com/kubernetes/kubernetes$ file:has.content(Copyright) kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:has.content%28Copyright%29+kubelet&patternType=keyword) | +| **file:has.owner(...)** | Conditionally search files only if they are owned by the given owner. Empty means _any owner_. See [code ownership documentation](/code-ownership) for more | `file:has.owner(alice@example.com) kubelet` | +| **file:has.contributor(...)** | Conditionally search files only if a file contributor's name or email matches the provided regex pattern. See [built-in predicates](/code-search/queries/language#built-in-file-predicate) for more | [`repo:^github\.com/kubernetes/kubernetes$ file:has.contributor(google\.com) kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:has.contributor%28google%5C.com%29+kubelet&patternType=keyword) | +| **count:_N_,< /> count:all** | Retrieve N results. By default, Sourcegraph stops searching early and returns if it finds a full page of results. This is desirable for most interactive searches. To wait for all results, use **count:all** | [`repo:^github\.com/kubernetes/kubernetes$ count:1000 function`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+count:1000+function&patternType=keyword)
[`repo:^github\.com/kubernetes/kubernetes$ count:all err`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+count:all+err&patternType=keyword) | +| **timeout:_go-duration-value_** | Customizes the timeout for searches. The value of the parameter is a string that can be parsed by the [Go time package's `ParseDuration`](https://golang.org/pkg/time/#ParseDuration) (e.g. 10s, 100ms). By default, the timeout is set to 10 seconds, and the search will optimize for returning results as soon as possible. The timeout value cannot be set longer than 1 minute. When provided, the search is given the full timeout to complete | [`repo:^github\.com/kubernetes/ timeout:15s func count:10000`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+timeout:15s+func+count:10000&patternType=keyword) | +| **patterntype:keyword, patterntype:regexp** | Configure your query to be interpreted as a keyword search, or a regular expression. Note: this filter is available as an accessibility option in addition to the visual toggles | [`repo:^github\.com/kubernetes/kubernetes$ test. patternType:keyword`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+test.+patternType:keyword&patternType=keyword)
[`repo:^github\.com/kubernetes/kubernetes$ (open\|close)file patternType:regexp`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%28open%7Cclose%29file+patternType:regexp&patternType=keyword) | +| **visibility:any, visibility:public, visibility:private** | Filter results to only public or private repositories. The default is to include both private and public repositories | [`repo:^github\.com/kubernetes/ type:repo visibility:public`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+type:repo+visibility:public&patternType=keyword) | + +Multiple or combined **repo:** and **file:** filters are intersected. For example, `repo:kubernetes repo:client` limits your search to repositories whose path contains **both** `kubernetes` and `client` (such as `github.com/kubernetes-client/csharp`). To include results from repositories whose path contains **either** pattern, use `|`, for example `repo:kubernetes/kubernetes$|microsoft/vscode$`. ## Boolean operators Use boolean operators to create more expressive searches. -| **Operator** | **Example** | -| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `and`, `AND` | [`conf.Get( and log15.Error(`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+conf.Get%28+and+log15.Error%28&patternType=regexp), [`conf.Get( and log15.Error( and after`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+conf.Get%28+and+log15.Error%28+and+after&patternType=regexp) | +| **Operator** | **Example** | +| ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `and`, `AND` | [`repo:^github\.com/kubernetes/kubernetes$ klog.ErrorS( and context.WithTimeout(`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+klog.ErrorS%28+and+context.WithTimeout%28&patternType=keyword), [`repo:^github\.com/kubernetes/kubernetes$ klog.ErrorS( and context.WithTimeout( and retry`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+klog.ErrorS%28+and+context.WithTimeout%28+and+retry&patternType=keyword) | Returns results for files containing matches on the left _and_ right side of the `and` (set intersection). -| **Operator** | **Example** | -| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `or`, `OR` | [`conf.Get( or log15.Error(`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+conf.Get%28+or+log15.Error%28&patternType=regexp), [conf.Get( or log15.Error( or after ](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+conf.Get%28+or+log15.Error%28+or+after&patternType=regexp) | +| **Operator** | **Example** | +| ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `or`, `OR` | [`repo:^github\.com/kubernetes/kubernetes$ klog.ErrorS( or context.WithTimeout(`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+klog.ErrorS%28+or+context.WithTimeout%28&patternType=keyword), [`repo:^github\.com/kubernetes/kubernetes$ klog.ErrorS( or context.WithTimeout( or retry`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+klog.ErrorS%28+or+context.WithTimeout%28+or+retry&patternType=keyword) | -Returns file content matching either on the left or right side, or both (set union). The number of results reports the number of matches of both strings. Note the regex or operator `|` may not work as expected with certain operators for example `file:(internal/repos)|(internal/gitserver)`, to receive the expected results use [subexpressions](/code-search/working/search-subexpressions), `(file:internal/repos or file:internal/gitserver)` +Returns file content matching either on the left or right side, or both (set union). The number of results reports the number of matches of both strings. Note the regex or operator `|` may not work as expected with certain operators for example `file:(pkg/kubelet)|(pkg/scheduler)`, to receive the expected results use [subexpressions](/code-search/working/search-subexpressions), `(file:pkg/kubelet or file:pkg/scheduler)` -| **Operator** | **Example** | -| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `not`, `NOT` | [`lang:go not file:main.go panic`](https://sourcegraph.com/search?q=lang:go+not+file:main.go+panic&patternType=keyword), [`panic NOT ever`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+panic+not+ever&patternType=keyword) | +| **Operator** | **Example** | +| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `not`, `NOT` | [`repo:^github\.com/kubernetes/kubernetes$ lang:go not file:main.go panic`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+lang:go+not+file:main.go+panic&patternType=keyword), [`repo:^github\.com/kubernetes/kubernetes$ panic NOT ever`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+panic+NOT+ever&patternType=keyword) | `NOT` can be used in place of `-` to negate filters, such as `file`, `content`, `lang`, `repohasfile`, and `repo`. For search patterns, `NOT` excludes documents that contain the term after `NOT`. For readability, you can also include the @@ -225,23 +217,23 @@ To apply the scope of the `file` filter to the entire subexpression, fully group The following filters are only used for **commit diff** and **commit message** searches, which show changes over time: -| **Filter** | **Description** | **Examples** | -| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| **repo:regexp-pattern@rev** | Specifies which Git revisions to search for commits. See our [repository revisions](#repository-revisions) documentation to learn more about the revision syntax. | [`repo:vscode@*refs/heads/:^refs/heads/main type:diff task`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/microsoft/vscode%24%40*refs/heads/:%5Erefs/heads/main+type:diff+after:%221+month+ago%22+task) (unmerged commit diffs containing `task`) | -| **type:diff**
**type:commit** | Specifies the type of search. By default, searches are executed on all code at a given point in time (a branch or a commit). Specify the `type:` if you want to search over changes to code or commit messages instead (diffs or commits). | [`type:diff func`](https://sourcegraph.com/search?q=type:diff+func+repo:sourcegraph/sourcegraph$)
[`type:commit test`](https://sourcegraph.com/search?q=type:commit+test+repo:sourcegraph/sourcegraph$) | -| **author:name** | Only include results from diffs or commits authored by the user. Regexps are supported. Note that they match the whole author string of the form `Full Name `, so to include only authors from a specific domain, use `author:example.com>$`. You can also use `author:@SourcegraphUserName` to search on a Sourcegraph user's list of verified emails.

You can also search by `committer:git-email`. _Note: there is a committer only when they are a different user than the author._ | [`type:diff author:nick`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick) | -| **-author:name** | Exclude results from diffs or commits authored by the user. Regexps are supported. Note that they match the whole author string of the form `Full Name `, so to exclude authors from a specific domain, use `author:example.com>$`. You can also use `author:@SourcegraphUserName` to search on a Sourcegraph user's list of verified emails.

You can also search by `committer:git-email`. _Note: there is a committer only when they are a different user than the author._ | [`type:diff author:nick`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick) | -| **before:"string specifying time frame"** | Only include results from diffs or commits which have a commit date before the specified time frame | [`type:diff before:"last thursday"`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick+before:%22last+thursday%22)
[`type:diff before:"november 1 2019"`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick+before:%22november+1+2019%22) | -| **after:"string specifying time frame"** | Only include results from diffs or commits which have a commit date after the specified time frame | [`type:diff after:"6 weeks ago"`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick+after:%226+weeks+ago%22)
[`type:diff after:"november 1 2019"`](https://sourcegraph.com/search?q=repo:sourcegraph/sourcegraph$+type:diff+author:nick+after:%22november+1+2019%22) | -| **message:"any string"** | Only include results from diffs or commits which have commit messages containing the string | [`type:commit message:"testing"`](https://sourcegraph.com/search?q=type:commit+repo:sourcegraph/sourcegraph$+message:%22testing%22)
[`type:diff message:"testing"`](https://sourcegraph.com/search?q=type:diff+repo:sourcegraph/sourcegraph$+message:%22testing%22) | -| **-message:"any string"** | Exclude the results from diffs or commits which have commit messages containing the string | [`type:commit message:"testing"`](https://sourcegraph.com/search?q=type:commit+repo:sourcegraph/sourcegraph$+message:%22testing%22)
[`type:diff message:"testing"`](https://sourcegraph.com/search?q=type:diff+repo:sourcegraph/sourcegraph$+message:%22testing%22) | +| **Filter** | **Description** | **Examples** | +| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| **repo:regexp-pattern@rev** | Specifies which Git revisions to search for commits. See our [repository revisions](#repository-revisions) documentation to learn more about the revision syntax. | [`repo:^github\.com/microsoft/vscode$@*refs/heads/:^refs/heads/main type:diff after:"1 month ago" task`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/microsoft/vscode%24@*refs/heads/:%5Erefs/heads/main+type:diff+after:%221+month+ago%22+task&patternType=keyword) (unmerged commit diffs containing `task`) | +| **type:diff**
**type:commit** | Specifies the type of search. By default, searches are executed on all code at a given point in time (a branch or a commit). Specify the `type:` if you want to search over changes to code or commit messages instead (diffs or commits). | [`repo:^github\.com/kubernetes/kubernetes$ type:diff func`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:diff+func&patternType=keyword)
[`repo:^github\.com/kubernetes/kubernetes$ type:commit test`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+test&patternType=keyword) | +| **author:name** | Only include results from diffs or commits authored by the user. Regexps are supported. Note that they match the whole author string of the form `Full Name `, so to include only authors from a specific domain, use `author:example.com>$`. You can also use `author:@SourcegraphUserName` to search on a Sourcegraph user's list of verified emails.

You can also search by `committer:git-email`. _Note: there is a committer only when they are a different user than the author._ | [`repo:^github\.com/kubernetes/kubernetes$ type:commit author:k8s-ci-robot`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+author:k8s-ci-robot&patternType=keyword) | +| **-author:name** | Exclude results from diffs or commits authored by the user. Regexps are supported. Note that they match the whole author string of the form `Full Name `, so to exclude authors from a specific domain, use `author:example.com>$`. You can also use `author:@SourcegraphUserName` to search on a Sourcegraph user's list of verified emails.

You can also search by `committer:git-email`. _Note: there is a committer only when they are a different user than the author._ | [`repo:^github\.com/kubernetes/kubernetes$ type:commit -author:k8s-ci-robot`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+-author:k8s-ci-robot&patternType=keyword) | +| **before:"string specifying time frame"** | Only include results from diffs or commits which have a commit date before the specified time frame | [`repo:^github\.com/kubernetes/kubernetes$ type:commit before:"last thursday"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+before:%22last+thursday%22&patternType=keyword)
[`repo:^github\.com/kubernetes/kubernetes$ type:commit before:"november 1 2019"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+before:%22november+1+2019%22&patternType=keyword) | +| **after:"string specifying time frame"** | Only include results from diffs or commits which have a commit date after the specified time frame | [`repo:^github\.com/kubernetes/kubernetes$ type:commit after:"6 weeks ago"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+after:%226+weeks+ago%22&patternType=keyword)
[`repo:^github\.com/kubernetes/kubernetes$ type:commit after:"november 1 2019"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+after:%22november+1+2019%22&patternType=keyword) | +| **message:"any string"** | Only include results from diffs or commits which have commit messages containing the string | [`repo:^github\.com/kubernetes/kubernetes$ type:commit message:"testing"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+message:%22testing%22&patternType=keyword)
[`repo:^github\.com/kubernetes/kubernetes$ type:diff message:"testing"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:diff+message:%22testing%22&patternType=keyword) | +| **-message:"any string"** | Exclude the results from diffs or commits which have commit messages containing the string | [`repo:^github\.com/kubernetes/kubernetes$ type:commit -message:"Merge pull request"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:commit+-message:%22Merge+pull+request%22&patternType=keyword)
[`repo:^github\.com/kubernetes/kubernetes$ type:diff -message:"Merge pull request"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:diff+-message:%22Merge+pull+request%22&patternType=keyword) | ## Repository Search ### Repository Revisions To search revisions other than the default branch, specify the revisions by either appending them to the -`repo:` filter or by listing them separately with the `rev:` filter. This means: `repo:github.com/myteam/abc@` is equivalent to `repo:github.com/myteam/abc rev:`. +`repo:` filter or by listing them separately with the `rev:` filter. This means: `repo:github.com/kubernetes/kubernetes@` is equivalent to `repo:github.com/kubernetes/kubernetes rev:`. The `` part refers to repository revisions (branches, commit hashes, and tags) and may take on the following forms: @@ -261,22 +253,22 @@ with `3.18`, but not a branch called `3.18` and vice versa for `@refs/heads/3.18 **Glob patterns** allow you to search over a range of branches or tags. Prepend `*` to mark a revision as glob pattern and add the glob-pattern after it like this `repo:@*`. For example: -- [`@*refs/heads/*`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/zoekt%24%40*refs/heads/*+ctags&patternType=keyword) - search across all branches -- [`@*refs/tags/*`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/src-cli%24%40*refs/tags/*+SRC_ENDPOINT&patternType=keyword) - search across all tags +- [`repo:^github\.com/kubernetes/kubernetes$@*refs/heads/* kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24@*refs/heads/*+kubelet&patternType=keyword) - search across all branches +- [`repo:^github\.com/kubernetes/kubernetes$@*refs/tags/* kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24@*refs/tags/*+kubelet&patternType=keyword) - search across all tags We automatically add a trailing `/*` if it is missing from the glob pattern. You can negate a glob pattern by prepending `*!`, for example: -- [`@*refs/heads/*:*!refs/heads/release* type:commit `](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24%40*refs/heads/*:*%21refs/heads/release*+type:commit+&patternType=keyword) - search commits on all branches except on those that start with "release" -- [`@*refs/tags/v3.*:*!refs/tags/v3.*-* context`](https://sourcegraph.com/search?q=repo:%5Egithub.com/sourcegraph/sourcegraph%24%40*refs/tags/v3.*:*%21refs/tags/v3.*-*+context&patternType=keyword) - search all versions starting with `3.` except release candidates, alpha and beta versions. +- [`repo:^github\.com/kubernetes/kubernetes$@*refs/heads/*:*!refs/heads/release* type:commit`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24@*refs/heads/*:*!refs/heads/release*+type:commit&patternType=keyword) - search commits on all branches except on those that start with "release" +- [`repo:^github\.com/kubernetes/kubernetes$@*refs/tags/v1.31.*:*!refs/tags/v1.31.*-* kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24@*refs/tags/v1.31.*:*!refs/tags/v1.31.*-*+kubelet&patternType=keyword) - search all `v1.31.` versions except release candidates, alpha, and beta versions. ### Repository names A query with only `repo:` filters returns a list of repositories with matching names. -- Example: [`repo:docker repo:registry`](https://sourcegraph.com/search?q=repo:docker+repo:registry) matches repositories with names that contain both `docker` and `registry` substrings -- Example: [`repo:docker OR repo:registry`](https://sourcegraph.com/search?q=repo:docker+OR+repo:registry&patternType=keyword) matches repositories with names that contain either `docker` or `registry` substrings +- Example: [`repo:kubernetes repo:client`](https://sourcegraph.com/search?q=repo:kubernetes+repo:client&patternType=keyword) matches repositories with names that contain both `kubernetes` and `client` substrings +- Example: [`repo:kubernetes OR repo:vscode`](https://sourcegraph.com/search?q=repo:kubernetes+OR+repo:vscode&patternType=keyword) matches repositories with names that contain either `kubernetes` or `vscode` substrings ### Commit and Diff searches @@ -285,17 +277,17 @@ contains all commits reachable from that revision. A commit is reachable from an reached by following the pointers to parent commits. For commit and diff searches it is possible to exclude a set of commits by prepending a caret `^`. The caret acts as a set -difference. For example, `repo:github.com/myteam/abc@main:^3.15 type:commit` will show all commits in `main` -minus the commits reachable from the commit tagged with `3.15`. +difference. For example, `repo:^github\.com/kubernetes/kubernetes$@release-1.33:^v1.33.0 type:commit` shows all commits in `release-1.33` +minus the commits reachable from the commit tagged with `v1.33.0`. ## Filename Search A query with `type:path` restricts terms to matching filenames only (not file contents). -- Example: [`type:path repo:/docker/ registry`](https://sourcegraph.com/search?q=type:path+repo:/docker/+registry) +- Example: [`repo:^github\.com/kubernetes/kubernetes$ type:path kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:path+kubelet&patternType=keyword) ## Content Search A query with `type:file` restricts terms to matching file contents only (not filenames). -- Example: [`type:file repo:^github\.com/sourcegraph/about$ website`](https://sourcegraph.com/search?q=type:file+repo:%5Egithub%5C.com/sourcegraph/about%24+website&patternType=keyword) +- Example: [`repo:^github\.com/kubernetes/kubernetes$ type:file kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:file+kubelet&patternType=keyword) From eb9a5e62fe519d23780980099917fabf399abdb6 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Fri, 30 Oct 2026 20:19:29 +0000 Subject: [PATCH 3/5] Use public repositories in ownership and Search Jobs examples Regenerate the Search Jobs results sample from a real search job on kubernetes/kubernetes, replacing output from a private repository, and show file:has.owner with microsoft/vscode, which has a CODEOWNERS file. Ownership search reads owners only from CODEOWNERS files. Amp-Thread-ID: https://ampcode.com/threads/T-1f043295-17f3-4f30-b014-ca3aff6606c2 Co-authored-by: Amp --- cspell-allow-list.txt | 2 ++ docs/code-search/queries/index.mdx | 2 +- docs/code-search/types/search-jobs.mdx | 8 ++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cspell-allow-list.txt b/cspell-allow-list.txt index a0532ab32..cde06d0c6 100644 --- a/cspell-allow-list.txt +++ b/cspell-allow-list.txt @@ -295,6 +295,7 @@ Kitts klog kubeconfig kubelet +kuberuntime kustomization Langbase languagemodels @@ -600,6 +601,7 @@ urlencode urlsafe userprincipalname USERTRUST +utilruntime Valsorda vegeta vercel diff --git a/docs/code-search/queries/index.mdx b/docs/code-search/queries/index.mdx index 02fe151ea..6660e529b 100644 --- a/docs/code-search/queries/index.mdx +++ b/docs/code-search/queries/index.mdx @@ -150,7 +150,7 @@ The following filters can be used on all searches (using [RE2 syntax](https://go | **repo:has.commit.after(...)** | Filter out stale repositories that don't contain commits past the specified time frame. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`repo:^github\.com/kubernetes/ repo:has.commit.after(yesterday)`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.commit.after%28yesterday%29&patternType=keyword)
[`repo:^github\.com/kubernetes/ repo:has.commit.after(june 25 2017)`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.commit.after%28june+25+2017%29&patternType=keyword) | | **rev:at.time(...)** | Search a repo or a branch at a specific point in time. Requires a `repo:` filter. The optional second argument is the revision to start from. | [`repo:^github\.com/kubernetes/kubernetes$ rev:at.time(1 year ago) kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:at.time%281+year+ago%29+kubelet&patternType=keyword)
[`repo:^github\.com/kubernetes/kubernetes$ rev:at.time(2024-01-01, release-1.29) kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:at.time%282024-01-01,+release-1.29%29+kubelet&patternType=keyword) | | **file:has.content(...)** | Conditionally search files only if they contain contents that match the provided regex pattern. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`repo:^github\.com/kubernetes/kubernetes$ file:has.content(Copyright) kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:has.content%28Copyright%29+kubelet&patternType=keyword) | -| **file:has.owner(...)** | Conditionally search files only if they are owned by the given owner. Empty means _any owner_. See [code ownership documentation](/code-ownership) for more | `file:has.owner(alice@example.com) kubelet` | +| **file:has.owner(...)** | Conditionally search files only if the repository's CODEOWNERS file assigns them to the given owner. Empty means _any owner_. See [code ownership documentation](/code-ownership) for more | `repo:^github\.com/microsoft/vscode$ file:has.owner() registerCommand` | | **file:has.contributor(...)** | Conditionally search files only if a file contributor's name or email matches the provided regex pattern. See [built-in predicates](/code-search/queries/language#built-in-file-predicate) for more | [`repo:^github\.com/kubernetes/kubernetes$ file:has.contributor(google\.com) kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:has.contributor%28google%5C.com%29+kubelet&patternType=keyword) | | **count:_N_,< /> count:all** | Retrieve N results. By default, Sourcegraph stops searching early and returns if it finds a full page of results. This is desirable for most interactive searches. To wait for all results, use **count:all** | [`repo:^github\.com/kubernetes/kubernetes$ count:1000 function`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+count:1000+function&patternType=keyword)
[`repo:^github\.com/kubernetes/kubernetes$ count:all err`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+count:all+err&patternType=keyword) | | **timeout:_go-duration-value_** | Customizes the timeout for searches. The value of the parameter is a string that can be parsed by the [Go time package's `ParseDuration`](https://golang.org/pkg/time/#ParseDuration) (e.g. 10s, 100ms). By default, the timeout is set to 10 seconds, and the search will optimize for returning results as soon as possible. The timeout value cannot be set longer than 1 minute. When provided, the search is given the full timeout to complete | [`repo:^github\.com/kubernetes/ timeout:15s func count:10000`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+timeout:15s+func+count:10000&patternType=keyword) | diff --git a/docs/code-search/types/search-jobs.mdx b/docs/code-search/types/search-jobs.mdx index ef281aa2f..1b7c74d1f 100644 --- a/docs/code-search/types/search-jobs.mdx +++ b/docs/code-search/types/search-jobs.mdx @@ -28,12 +28,12 @@ To use Search Jobs: The downloaded results are formatted as [JSON lines](https://jsonlines.org). The JSON objects have the same format as the (event-type) matches served by the [Stream API](/api/stream-api#event-types). -Here is an example of a JSON lines results file for a search job that ran the query `r:github.com/sourcegraph/sourcegraph handlePanic`. -The search returned 4 results in 2 files: +Here is an example of a JSON lines results file for a search job that ran the query `repo:^github\.com/kubernetes/kubernetes$ HandleCrash file:^pkg/kubelet/`. +The search returned 8 results in 6 files. These are the first 2 lines: ```json lines -{"type":"content","path":"cmd/symbols/shared/main.go","repositoryID":399,"repository":"github.com/sourcegraph/sourcegraph","branches":["HEAD"],"commit":"9b47c6430cc3c9cb16695b4fa0a1a277cbbdb327","hunks":null,"chunkMatches":[{"content":"func handlePanic(logger log.Logger, next http.Handler) http.Handler {","contentStart":{"offset":4526,"line":129,"column":0},"ranges":[{"start":{"offset":4531,"line":129,"column":5},"end":{"offset":4542,"line":129,"column":16}}]},{"content":"\thandler = handlePanic(logger, handler)","contentStart":{"offset":3570,"line":98,"column":0},"ranges":[{"start":{"offset":3581,"line":98,"column":11},"end":{"offset":3592,"line":98,"column":22}}]}],"language":"Go"} -{"type":"content","path":"cmd/embeddings/shared/main.go","repositoryID":399,"repository":"github.com/sourcegraph/sourcegraph","branches":["HEAD"],"commit":"9b47c6430cc3c9cb16695b4fa0a1a277cbbdb327","hunks":null,"chunkMatches":[{"content":"func handlePanic(logger log.Logger, next http.Handler) http.Handler {","contentStart":{"offset":6585,"line":190,"column":0},"ranges":[{"start":{"offset":6590,"line":190,"column":5},"end":{"offset":6601,"line":190,"column":16}}]},{"content":"\thandler = handlePanic(logger, handler)","contentStart":{"offset":2844,"line":81,"column":0},"ranges":[{"start":{"offset":2855,"line":81,"column":11},"end":{"offset":2866,"line":81,"column":22}}]}],"language":"Go"} +{"type":"content","path":"pkg/kubelet/kuberuntime/kuberuntime_container.go","pathMatches":[{"start":{"offset":0,"line":0,"column":0},"end":{"offset":12,"line":0,"column":12}}],"repositoryID":142561,"repository":"github.com/kubernetes/kubernetes","externalServiceType":"github","branches":["HEAD"],"commit":"ba832c18b978efaf9ce60a9c91a7326e77050483","hunks":null,"chunkMatches":[{"content":"\t\tdefer utilruntime.HandleCrashWithContext(ctx)\n","contentStart":{"offset":33450,"line":800,"column":0},"ranges":[{"start":{"offset":33470,"line":800,"column":20},"end":{"offset":33481,"line":800,"column":31}}],"bestLineMatch":800},{"content":"\t\t\tdefer utilruntime.HandleCrashWithContext(ctx)\n","contentStart":{"offset":40588,"line":956,"column":0},"ranges":[{"start":{"offset":40609,"line":956,"column":21},"end":{"offset":40620,"line":956,"column":32}}],"bestLineMatch":956}],"language":"Go"} +{"type":"content","path":"pkg/kubelet/pod_workers.go","pathMatches":[{"start":{"offset":0,"line":0,"column":0},"end":{"offset":12,"line":0,"column":12}}],"repositoryID":142561,"repository":"github.com/kubernetes/kubernetes","externalServiceType":"github","branches":["HEAD"],"commit":"ba832c18b978efaf9ce60a9c91a7326e77050483","hunks":null,"chunkMatches":[{"content":"\t\t\tdefer runtime.HandleCrash()\n","contentStart":{"offset":44791,"line":986,"column":0},"ranges":[{"start":{"offset":44808,"line":986,"column":17},"end":{"offset":44819,"line":986,"column":28}}],"bestLineMatch":986}],"language":"Go"} ``` ## Supported result types From 8554ac646d05b94baad8b403591efb536d78777c Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Fri, 30 Oct 2026 23:58:27 +0000 Subject: [PATCH 4/5] Update code ownership docs for CODEOWNERS-only ownership Remove the leftover reference to a second way of configuring ownership, state that ownership comes only from committed CODEOWNERS files and which file wins when several exist, and replace examples that searched a private repository with grafana/grafana examples that run on Sourcegraph.com. Fix the list of predicates without parameters. Amp-Thread-ID: https://ampcode.com/threads/T-1f043295-17f3-4f30-b014-ca3aff6606c2 Co-authored-by: Amp --- cspell-allow-list.txt | 1 + docs/code-ownership/codeowners-format.mdx | 8 +++----- docs/code-ownership/index.mdx | 24 ++++++++++++----------- docs/code-search/queries/index.mdx | 2 +- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/cspell-allow-list.txt b/cspell-allow-list.txt index cde06d0c6..2f2b27072 100644 --- a/cspell-allow-list.txt +++ b/cspell-allow-list.txt @@ -58,6 +58,7 @@ Awais awscli awsrepos azuredevops +azuremonitor backfiller baseai batchchange diff --git a/docs/code-ownership/codeowners-format.mdx b/docs/code-ownership/codeowners-format.mdx index fc7233561..aff0e1519 100644 --- a/docs/code-ownership/codeowners-format.mdx +++ b/docs/code-ownership/codeowners-format.mdx @@ -44,13 +44,9 @@ The rules are considered independently and in order. Rules farther down the file - GitLab allows sections in `CODEOWNERS` files, these are not yet supported and section markers are ignored - [Code Owners for Bitbucket](https://marketplace.atlassian.com/apps/1218598/code-owners-for-bitbucket?tab=overview&hosting=cloud) inline defined groups are not yet supported -To configure ownership in Sourcegraph, you have two options: - ## Committing a `CODEOWNERS` file to your repositories -> Use this approach if you prefer versioned ownership data. - -You can simply commit a `CODEOWNERS` file at any of the following locations for it to be picked up automatically by code ownership: +Sourcegraph reads ownership only from `CODEOWNERS` files committed to your repositories. Commit a `CODEOWNERS` file at any of the following locations for it to be picked up automatically by code ownership: ``` CODEOWNERS @@ -59,4 +55,6 @@ CODEOWNERS docs/CODEOWNERS ``` +If a repository has `CODEOWNERS` files at more than one of these locations, Sourcegraph uses the first one in this list. + Searches at specific commits will return any `CODEOWNERS` data that exists at that specific commit. diff --git a/docs/code-ownership/index.mdx b/docs/code-ownership/index.mdx index f1fa83f4a..2bc14d5c2 100644 --- a/docs/code-ownership/index.mdx +++ b/docs/code-ownership/index.mdx @@ -23,7 +23,7 @@ Code ownership is set via [the `CODEOWNERS` format](/code-ownership/codeowners-f The ownership information is available for browsing once ownership data is available through [a `CODEOWNERS` file](#code-ownership). -When displaying a source file, there is an "Ownership" button at the bottom. Clicking it will open the "Ownership" panel. +When displaying a source file, there is an "Ownership" button at the bottom. Clicking it will open the "Ownership" panel. The button appears only in repositories that have a `CODEOWNERS` file. ![File view with the ownership tab selected in the bottom panel](https://storage.googleapis.com/sourcegraph-assets/docs/own/blob-view-panel-v2.png) @@ -33,22 +33,24 @@ When displaying a source file, there is an "Ownership" button at the bottom. Cli Code ownership is a first-class citizen in search. Ownership can be either a query input or a search result: -- `file:has.owner(user@example.com)` keeps only the search results associated with given user (here referred to by e-mail). -- `-file:has.owner(@username)` removes all results owned by specific user (here referred to by name). +| Predicate | Keeps | Example | +| --- | --- | --- | +| `file:has.owner(...)` | Results owned by the given owner | [`repo:^github\.com/grafana/grafana$ file:has.owner(grafana/data-sources-plugins) azure count:10`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/grafana/grafana%24+file:has.owner%28grafana/data-sources-plugins%29+azure+count:10&patternType=keyword) | +| `-file:has.owner(...)` | Results not owned by the given owner | [`repo:^github\.com/grafana/grafana$ -file:has.owner(grafana/data-sources-plugins) azure count:10`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/grafana/grafana%24+-file:has.owner%28grafana/data-sources-plugins%29+azure+count:10&patternType=keyword) | +| `file:has.owner()` | Files that have an owner | [`repo:^github\.com/grafana/grafana$ file:has.owner() azure count:10`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/grafana/grafana%24+file:has.owner%28%29+azure+count:10&patternType=keyword) | +| `-file:has.owner()` | Files without an owner | [`repo:^github\.com/grafana/grafana$ -file:has.owner() azure count:10`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/grafana/grafana%24+-file:has.owner%28%29+azure+count:10&patternType=keyword) | -Ownership predicate can also be used without parameters: +Write the owner as the complete username, team name, or email address from the `CODEOWNERS` file. The leading `@` is optional. --`file:has.owner()` will only include files with an owner assigned to them. -`-file:has.owner()` will only include files without an owner. +When performing a search, the `select:file.owners` predicate returns the owners of the search results. For example, to find the owners of Go files in the `pkg/tsdb/azuremonitor/` directory: -When performing a search the `select:file.owners` predicate will return the owners for the result of that search. +[`repo:^github\.com/grafana/grafana$ file:^pkg/tsdb/azuremonitor/ lang:go select:file.owners count:50`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/grafana/grafana%24+file:%5Epkg/tsdb/azuremonitor/+lang:go+select:file.owners+count:50&patternType=keyword) -For instance one can find all the owners of TypeScript files in a given repository by using `repo:^github\.com/sourcegraph/sourcegraph$ lang:TypeScript select:file.owners`. +### Find commits in a release for a given owner -### Find commits in given release for given owner +With `type:commit`, `file:has.owner(...)` matches commits that changed files owned by the given owner. For example, to find the commits between versions `v12.4.13` and `v12.4.14` that changed files owned by the `grafana/grafana-frontend-platform` team: -To find all commits between versions `5.0` and `5.1` made by `sourcegraph/own` team, the following query could be used: - -`repo:^github\.com/sourcegraph/sourcegraph$@5.1:^5.0 type:commit file:has.owner(sourcegraph/own)` +[`repo:^github\.com/grafana/grafana$@v12.4.14:^v12.4.13 type:commit file:has.owner(grafana/grafana-frontend-platform)`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/grafana/grafana%24@v12.4.14:%5Ev12.4.13+type:commit+file:has.owner%28grafana/grafana-frontend-platform%29&patternType=keyword) ## Further reading diff --git a/docs/code-search/queries/index.mdx b/docs/code-search/queries/index.mdx index 6660e529b..6e237a731 100644 --- a/docs/code-search/queries/index.mdx +++ b/docs/code-search/queries/index.mdx @@ -150,7 +150,7 @@ The following filters can be used on all searches (using [RE2 syntax](https://go | **repo:has.commit.after(...)** | Filter out stale repositories that don't contain commits past the specified time frame. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`repo:^github\.com/kubernetes/ repo:has.commit.after(yesterday)`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.commit.after%28yesterday%29&patternType=keyword)
[`repo:^github\.com/kubernetes/ repo:has.commit.after(june 25 2017)`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.commit.after%28june+25+2017%29&patternType=keyword) | | **rev:at.time(...)** | Search a repo or a branch at a specific point in time. Requires a `repo:` filter. The optional second argument is the revision to start from. | [`repo:^github\.com/kubernetes/kubernetes$ rev:at.time(1 year ago) kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:at.time%281+year+ago%29+kubelet&patternType=keyword)
[`repo:^github\.com/kubernetes/kubernetes$ rev:at.time(2024-01-01, release-1.29) kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:at.time%282024-01-01,+release-1.29%29+kubelet&patternType=keyword) | | **file:has.content(...)** | Conditionally search files only if they contain contents that match the provided regex pattern. See [built-in predicates](/code-search/queries/language#built-in-repo-predicate) for more | [`repo:^github\.com/kubernetes/kubernetes$ file:has.content(Copyright) kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:has.content%28Copyright%29+kubelet&patternType=keyword) | -| **file:has.owner(...)** | Conditionally search files only if the repository's CODEOWNERS file assigns them to the given owner. Empty means _any owner_. See [code ownership documentation](/code-ownership) for more | `repo:^github\.com/microsoft/vscode$ file:has.owner() registerCommand` | +| **file:has.owner(...)** | Conditionally search files only if the repository's CODEOWNERS file assigns them to the given owner. Empty means _any owner_. See [code ownership documentation](/code-ownership) for more | [`repo:^github\.com/grafana/grafana$ file:has.owner(grafana/data-sources-plugins) azure count:10`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/grafana/grafana%24+file:has.owner%28grafana/data-sources-plugins%29+azure+count:10&patternType=keyword) | | **file:has.contributor(...)** | Conditionally search files only if a file contributor's name or email matches the provided regex pattern. See [built-in predicates](/code-search/queries/language#built-in-file-predicate) for more | [`repo:^github\.com/kubernetes/kubernetes$ file:has.contributor(google\.com) kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:has.contributor%28google%5C.com%29+kubelet&patternType=keyword) | | **count:_N_,< /> count:all** | Retrieve N results. By default, Sourcegraph stops searching early and returns if it finds a full page of results. This is desirable for most interactive searches. To wait for all results, use **count:all** | [`repo:^github\.com/kubernetes/kubernetes$ count:1000 function`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+count:1000+function&patternType=keyword)
[`repo:^github\.com/kubernetes/kubernetes$ count:all err`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+count:all+err&patternType=keyword) | | **timeout:_go-duration-value_** | Customizes the timeout for searches. The value of the parameter is a string that can be parsed by the [Go time package's `ParseDuration`](https://golang.org/pkg/time/#ParseDuration) (e.g. 10s, 100ms). By default, the timeout is set to 10 seconds, and the search will optimize for returning results as soon as possible. The timeout value cannot be set longer than 1 minute. When provided, the search is given the full timeout to complete | [`repo:^github\.com/kubernetes/ timeout:15s func count:10000`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+timeout:15s+func+count:10000&patternType=keyword) | From 52a795cbd457d871893acf8ff898a9d0e180bec7 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Sat, 31 Oct 2026 00:19:01 +0000 Subject: [PATCH 5/5] Show search query examples as lists instead of tables Long queries in narrow table columns wrapped onto several lines and squeezed the descriptions. Each example now gets a description line and a full-width query. Amp-Thread-ID: https://ampcode.com/threads/T-1f043295-17f3-4f30-b014-ca3aff6606c2 Co-authored-by: Amp --- docs/code-ownership/index.mdx | 16 ++++----- docs/code-search/queries/index.mdx | 57 ++++++++++++++++++------------ 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/docs/code-ownership/index.mdx b/docs/code-ownership/index.mdx index 2bc14d5c2..e7c71664c 100644 --- a/docs/code-ownership/index.mdx +++ b/docs/code-ownership/index.mdx @@ -33,14 +33,14 @@ When displaying a source file, there is an "Ownership" button at the bottom. Cli Code ownership is a first-class citizen in search. Ownership can be either a query input or a search result: -| Predicate | Keeps | Example | -| --- | --- | --- | -| `file:has.owner(...)` | Results owned by the given owner | [`repo:^github\.com/grafana/grafana$ file:has.owner(grafana/data-sources-plugins) azure count:10`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/grafana/grafana%24+file:has.owner%28grafana/data-sources-plugins%29+azure+count:10&patternType=keyword) | -| `-file:has.owner(...)` | Results not owned by the given owner | [`repo:^github\.com/grafana/grafana$ -file:has.owner(grafana/data-sources-plugins) azure count:10`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/grafana/grafana%24+-file:has.owner%28grafana/data-sources-plugins%29+azure+count:10&patternType=keyword) | -| `file:has.owner()` | Files that have an owner | [`repo:^github\.com/grafana/grafana$ file:has.owner() azure count:10`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/grafana/grafana%24+file:has.owner%28%29+azure+count:10&patternType=keyword) | -| `-file:has.owner()` | Files without an owner | [`repo:^github\.com/grafana/grafana$ -file:has.owner() azure count:10`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/grafana/grafana%24+-file:has.owner%28%29+azure+count:10&patternType=keyword) | - -Write the owner as the complete username, team name, or email address from the `CODEOWNERS` file. The leading `@` is optional. +- Results owned by the given owner:\ + [`repo:^github\.com/grafana/grafana$ file:has.owner(grafana/data-sources-plugins) azure count:10`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/grafana/grafana%24+file:has.owner%28grafana/data-sources-plugins%29+azure+count:10&patternType=keyword) +- Files that have an owner:\ + [`repo:^github\.com/grafana/grafana$ file:has.owner() azure count:10`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/grafana/grafana%24+file:has.owner%28%29+azure+count:10&patternType=keyword) +- Files without an owner:\ + [`repo:^github\.com/grafana/grafana$ -file:has.owner() azure count:10`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/grafana/grafana%24+-file:has.owner%28%29+azure+count:10&patternType=keyword) + +Write the owner as the complete username, team name, or email address from the `CODEOWNERS` file. The leading `@` is optional. To exclude results owned by the given owner, use `-file:has.owner(...)`. When performing a search, the `select:file.owners` predicate returns the owners of the search results. For example, to find the owners of Go files in the `pkg/tsdb/azuremonitor/` directory: diff --git a/docs/code-search/queries/index.mdx b/docs/code-search/queries/index.mdx index 6e237a731..419c5087a 100644 --- a/docs/code-search/queries/index.mdx +++ b/docs/code-search/queries/index.mdx @@ -23,26 +23,35 @@ The examples on this page search public repositories on Sourcegraph.com, mostly ### Find code -| To find | Query | -| ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Files that contain all terms, in any order | [`repo:^github\.com/kubernetes/kubernetes$ kubelet eviction`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+kubelet+eviction&patternType=keyword) | -| An exact phrase | [`repo:^github\.com/kubernetes/kubernetes$ "failed to sync pod"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%22failed+to+sync+pod%22&patternType=keyword) | -| A regular expression | [`repo:^github\.com/kubernetes/kubernetes$ /eviction.*threshold/`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+/eviction.*threshold/&patternType=keyword) | -| A combination of terms | [`repo:^github\.com/kubernetes/kubernetes$ (error OR warning) AND retry NOT deprecated`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%28error+OR+warning%29+AND+retry+NOT+deprecated&patternType=keyword) | -| Text in exactly this case | [`repo:^github\.com/kubernetes/kubernetes$ PodSpec case:yes`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+PodSpec+case:yes&patternType=keyword) | +- Files that contain all terms, in any order:\ + [`repo:^github\.com/kubernetes/kubernetes$ kubelet eviction`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+kubelet+eviction&patternType=keyword) +- An exact phrase:\ + [`repo:^github\.com/kubernetes/kubernetes$ "failed to sync pod"`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%22failed+to+sync+pod%22&patternType=keyword) +- A regular expression:\ + [`repo:^github\.com/kubernetes/kubernetes$ /eviction.*threshold/`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+/eviction.*threshold/&patternType=keyword) +- A combination of terms:\ + [`repo:^github\.com/kubernetes/kubernetes$ (error OR warning) AND retry NOT deprecated`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%28error+OR+warning%29+AND+retry+NOT+deprecated&patternType=keyword) +- Text in exactly this case:\ + [`repo:^github\.com/kubernetes/kubernetes$ PodSpec case:yes`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+PodSpec+case:yes&patternType=keyword) ### Narrow the search -| To search | Query | -| ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| One repository | [`repo:^github\.com/kubernetes/kubernetes$`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24&patternType=keyword) | -| Repositories that match a pattern, except some | [`repo:^github\.com/kubernetes/ -repo:kubernetes/website`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+-repo:kubernetes/website&patternType=keyword) | -| Files in repositories that contain a path | [`repo:^github\.com/kubernetes/ repo:has.path(\.py) file:Dockerfile`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.path%28%5C.py%29+file:Dockerfile&patternType=keyword) | -| Repositories with recent commits | [`repo:^github\.com/kubernetes/ repo:has.commit.after(1 month ago)`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.commit.after%281+month+ago%29&patternType=keyword) | -| One language | [`repo:^github\.com/microsoft/vscode$ lang:typescript registerCommand`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/microsoft/vscode%24+lang:typescript+registerCommand&patternType=keyword) | -| All languages except one | [`repo:^github\.com/kubernetes/kubernetes$ "feature gate" -lang:markdown`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%22feature+gate%22+-lang:markdown&patternType=keyword) | -| Symbol definitions | [`repo:^github\.com/kubernetes/kubernetes$ type:symbol NewKubeletCommand`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:symbol+NewKubeletCommand&patternType=keyword) | -| Files with an extension that contain a pattern | [`repo:^github\.com/kubernetes/kubernetes$ file:\.go$ file:has.content(TODO)`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:%5C.go%24+file:has.content%28TODO%29&patternType=keyword) | +- One repository:\ + [`repo:^github\.com/kubernetes/kubernetes$`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24&patternType=keyword) +- Repositories that match a pattern, except some:\ + [`repo:^github\.com/kubernetes/ -repo:kubernetes/website`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+-repo:kubernetes/website&patternType=keyword) +- Files in repositories that contain a path:\ + [`repo:^github\.com/kubernetes/ repo:has.path(\.py) file:Dockerfile`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.path%28%5C.py%29+file:Dockerfile&patternType=keyword) +- Repositories with recent commits:\ + [`repo:^github\.com/kubernetes/ repo:has.commit.after(1 month ago)`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/+repo:has.commit.after%281+month+ago%29&patternType=keyword) +- One language:\ + [`repo:^github\.com/microsoft/vscode$ lang:typescript registerCommand`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/microsoft/vscode%24+lang:typescript+registerCommand&patternType=keyword) +- All languages except one:\ + [`repo:^github\.com/kubernetes/kubernetes$ "feature gate" -lang:markdown`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+%22feature+gate%22+-lang:markdown&patternType=keyword) +- Symbol definitions:\ + [`repo:^github\.com/kubernetes/kubernetes$ type:symbol NewKubeletCommand`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+type:symbol+NewKubeletCommand&patternType=keyword) +- Files with an extension that contain a pattern:\ + [`repo:^github\.com/kubernetes/kubernetes$ file:\.go$ file:has.content(TODO)`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+file:%5C.go%24+file:has.content%28TODO%29&patternType=keyword) `repo:` and `file:` take regular expressions, so `repo:kubernetes/kubernetes` also matches `kubernetes/kubernetes-template-project`. Use `^` and `$` to match one repository. The argument of `file:has.content(...)` is also a regular expression, and quotes in it are matched literally: `file:has.content("TODO")` matches only files that contain `"TODO"` with the quotes. @@ -58,12 +67,14 @@ To list recently active Go repositories in the `kubernetes` organization that co Sourcegraph searches each repository's default branch unless the query has a `rev:` filter. A `rev:` filter needs a `repo:` filter in the same query. On its own, a query such as `rev:release-1.33` returns an `Invalid syntax` alert that asks for a `repo:` filter. -| To search | Query | -| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| A branch, tag, or commit | [`repo:^github\.com/kubernetes/kubernetes$ rev:release-1.33 kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:release-1.33+kubelet&patternType=keyword) | -| The default branch | [`repo:^github\.com/kubernetes/kubernetes$ rev:HEAD kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:HEAD+kubelet&patternType=keyword) | -| All branches | [`repo:^github\.com/kubernetes/kubernetes$ rev:*refs/heads/* kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:*refs/heads/*+kubelet&patternType=keyword) | -| All tags | [`repo:^github\.com/kubernetes/kubernetes$ rev:*refs/tags/* kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:*refs/tags/*+kubelet&patternType=keyword) | +- A branch, tag, or commit:\ + [`repo:^github\.com/kubernetes/kubernetes$ rev:release-1.33 kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:release-1.33+kubelet&patternType=keyword) +- The default branch:\ + [`repo:^github\.com/kubernetes/kubernetes$ rev:HEAD kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:HEAD+kubelet&patternType=keyword) +- All branches:\ + [`repo:^github\.com/kubernetes/kubernetes$ rev:*refs/heads/* kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:*refs/heads/*+kubelet&patternType=keyword) +- All tags:\ + [`repo:^github\.com/kubernetes/kubernetes$ rev:*refs/tags/* kubelet`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/kubernetes/kubernetes%24+rev:*refs/tags/*+kubelet&patternType=keyword) If some repositories that match `repo:` don't have the revision, Sourcegraph searches the others and lists the missing revisions under **Some revisions could not be searched**. For example, most repositories in the `kubernetes` organization don't have a `release-1.33` branch: