# Search syntax

> The complete query language for searching code in Corfedo, with every term, operator, filter, option, value and limit.

Source: https://docs.corfedo.ai/reference/search-syntax/

One query language applies everywhere you search code: the **Code search** page, the MCP tool `search_code`, `corfedo search` and [`POST /api/v1/search`](https://docs.corfedo.ai/reference/api/read/searchCode/). It follows Sourcegraph's keyword syntax, with the differences listed [at the end](#differences-from-sourcegraph).

## Examples

| Query | Finds |
| --- | --- |
| `where are webhook signatures verified` | Files about that behavior, the most relevant first |
| `RefundPolicy` | Files that declare or use the name, with its definition ranked high |
| `"connection refused"` | Files that contain the phrase |
| `/retry_\w+\(/` | Files where the regular expression matches |
| `retry lang:go -file:test` | Go files about retries, without tests |
| `"RetryPolicy" OR "BackoffPolicy"` | Files that contain either name |

## Terms

| Term | Matches |
| --- | --- |
| `retry backoff` | Files that use any of the words. Files that use more of them rank higher. |
| `"retry policy"` | Files that contain the phrase exactly, with its space |
| `/retry_\w+/` | Files where the regular expression matches |

Bare words are ranked by relevance. A file ranks higher when its code, the names it declares, its path and its file name use your words. A file that defines a name you typed, and files in the folders that match your words best, rank higher too. Tests, generated files and vendored code rank lower, unless your words mention tests or generated code.

A word matches where an identifier or a part of one starts with it, in any letter case: `retry` finds `RetryPolicy`, `max_retry` and `retrying`. A name written in code style, such as `RefundPolicy` or `refund_policy`, is looked up as an identifier, and one with capitals matches that letter case in code. Words match by their letters, digits and underscores. Words shorter than three characters and common words such as `how`, `where` and `find` are left out. Bare words that are all left out, such as `fn` in `lang:rust fn` or `fn OR retry`, are not searched. The rest of the query runs and the results name the text that was not searched. A query with nothing else to search is rejected. Quote text to find it as written, such as `"fn"`, `"--force"` or `"io"`.

The bare words of a query are read together wherever they stand: `retry lang:go backoff` ranks Go files for `retry backoff`. Phrases, patterns and filters beside them must each match.

A phrase is in double quotes. Inside it, `\"` is the quote, `\\` a backslash, and `\n`, `\r` and `\t` a line break, carriage return and tab. Other backslashes stay as written. Single quotes are ordinary characters, so `what's`, `'static` and `impl<'a>` are words. Quote a term that looks like syntax to search for it literally, for example `"AND"`, `"repo:x"` or `"/a/"`.

A regular expression starts with `/` at the start of a word and ends at the first `/` followed by a space, `)` or the end of the query, so it can hold spaces: `/fn spawn/`. Slashes after `\` or inside `[…]` do not end it. `/api/v1/search` has no such slash, so it is a word.

Phrases and regular expressions ignore letter case unless the query has `case:yes`. Regular expressions use RE2 syntax: backreferences and lookaround are not supported.

## Operators

| Operator | Meaning |
| --- | --- |
| `a AND b` | Both. `retry AND backoff` needs both words in a file. |
| `a OR b` | Either |
| `NOT a` | Excludes files that match `a` |
| `-a` | The same as `NOT a`, before a filter, phrase, regular expression or group: `-file:test`, `-"mock"`, `-(retry backoff)` |
| `( … )` | Groups terms |

Uppercase `AND`, `OR` and `NOT` are always operators. Lowercase `and` and `or` are operators only between phrases, regular expressions, filters and groups, and lowercase `not` only right before one: `"retry" or "backoff"`, `lang:go or lang:rust`, `retry not lang:go`. Elsewhere they are words, so `retry or backoff` searches for those three words. Other spellings, such as `Or`, are words.

A `-` before a word is part of the word: `-backoff` is a word.

`NOT` binds tighter than `AND`, and `AND` tighter than `OR`: `a OR b AND c` means `a OR (b AND c)`. Groups nest up to 16 levels.

Beside a top-level `OR`, the filters at the start or the end of the query apply to the whole query, as in Sourcegraph. `lang:go retry OR backoff` searches Go files for either word, and `repo:payments timeout OR deadline` searches `payments` for either word. `content:` and `kind:` stay in their alternative, and so does a filter that is an alternative on its own, as in `lang:go OR lang:rust`. A filter between the alternatives belongs to its alternative: in `retry lang:go OR backoff`, `lang:go` applies to `retry` only.

A negated term needs a positive term beside it in the same group. `retry -file:test` works. `-file:test` and `NOT retry` on their own are rejected.

## Code filters

These filters narrow which files match. Each takes `-` to negate it, and each can appear inside groups.

| Filter | Aliases | Value | Matches files |
| --- | --- | --- | --- |
| `file:` | `f:`, `path:` | Regular expression | Whose path matches, for example `file:\.go$` or `file:^src/` |
| `language:` | `lang:`, `l:` | [Language](#languages) | In that language |
| `sym:` | | Regular expression | That declare a symbol whose name matches, for example `sym:^Test` |
| `kind:` | | [Symbol kind](#symbol-kinds) | That declare a symbol of that kind |
| `content:` | `c:` | Phrase or `/regex/`. A word is read as a phrase. | That contain it exactly |

`file:` and `sym:` are not anchored. Add `^` or `$` to match the start or end. `content:` lets you search for text that looks like a filter, such as `content:"repo:x"`.

Filter and option names of two or more letters work in any letter case, such as `Lang:go`. One-letter aliases such as `f:` and `r:` are lowercase only, so `C:\Users` is ordinary text.

## Repository filters

Repository filters choose which repositories are searched. They apply to the whole query, so they cannot appear in a group with search terms. Beside a top-level `OR`, they work at the start or the end of a query without parentheses, as [operators](#operators) describe: `timeout OR deadline repo:payments`. Elsewhere, put the `OR` in a group: `repo:payments (timeout OR deadline)`. Each takes `-` to exclude what it matches.

To search any of several repositories, join repository filters with `or` in one group, such as `(org:acme or org:globex) retry` or `(repo:payments or context:"Backend services")`. The filters can be of different kinds. A group cannot hold `-` filters, `and` or another group. A query of only `repo:a or repo:b` needs no parentheses.

| Filter | Value | Selects repositories |
| --- | --- | --- |
| `repo:` (alias `r:`) | Regular expression | Whose full name matches, for example `repo:payments` or `repo:^github\.com/acme/` |
| `org:` | Owner or group path | Whose owner equals the value, for example `org:acme` or `org:team/subteam` |
| `context:` | Saved context name | In your saved context or the workspace context of that name. `context:global` is every repository and takes no `-`. |
| `depends_on:` | `ecosystem/package`, optionally `@` and a version constraint | That depend on the package |
| `affected_by:` | Advisory ID | That have an open finding for the advisory |
| `archived:` | `yes`, `no` or `only` | By archived state |
| `fork:` | `yes`, `no` or `only` | By fork state |
| `visibility:` | `any`, `public` or `private` | By visibility on the forge |

Every search starts from all the repositories you can read. Each filter or group narrows that set and each `-` filter removes repositories from it. A group keeps the repositories that match any of its filters. To search several repositories by name, you can also use one `repo:` alternation, such as `repo:^github\.com/acme/(api|web)$`.

A repository's full name is its forge host, any path prefix, and its name, for example `github.com/acme/payments`. `repo:` matches it in any letter case and anywhere in the name. `org:` compares the owner part, `acme` for `acme/payments`, in any letter case. A repository without an owner never matches `org:`.

A `repo:`, `org:` or `context:` filter that matches nothing you can read is ignored, and the results say so. In a group, the other filters still select.

Archived repositories and forks are included unless you filter them. `yes` includes them, `no` leaves them out, and `only` keeps nothing else.

### Dependencies and advisories

`depends_on:` takes an ecosystem and a package name: `depends_on:npm/react`, `depends_on:nuget/Npgsql`, `depends_on:pypi/requests`. Scoped names keep their slash: `depends_on:npm/@angular/core`. The ecosystems are `npm`, `cargo`, `pypi`, `maven`, `nuget`, `go`, `rubygems`, `packagist`, `pub`, `hex`, `hackage`, `swift`, `vcpkg`, `conan`, `docker`, `gradle`, `terraform`, `github-actions` and `pulumi`.

A repository matches when its indexed commit installs the package or declares it as a requirement. After `@`, an installed version must also match the constraint:

| Constraint | Matches |
| --- | --- |
| `1.2.3` or `=1.2.3` | Exactly that version |
| `!=1.2.3` | Any other version |
| `>1.2.3`, `>=1.2.3`, `<1.2.3`, `<=1.2.3` | Versions above or below it |
| `>=2.0.0,<2.17.1` | Versions that meet every condition |
| `<1.0.0\|\|>=2.0.0` | Versions that meet either side |
| `2.17.*` | The 2.17 series |

A bare version is always exact, even where a manifest would read it as a range (`1.2.3` in Cargo.toml means `^1.2.3`). Versions compare the way the ecosystem orders them, so `maven/…@1.0` matches `1.0.0`. Prereleases count like any other version: `<2.0.0` matches `2.0.0-rc.1`, as advisory ranges do. A bound with fewer parts is filled with zeros (`<2` is `<2.0.0`). To match a series, write `1.2.*`.

The ecosystem's own forms also work:

| Ecosystem | Forms |
| --- | --- |
| npm | npm ranges, such as `^1.2`, `~1.2.3` or `1.2.x` |
| PyPI | PEP 440 specifiers, such as `~=1.2` or `==1.2.*` |
| Cargo, Packagist | `^1.2` and `~1.2`, as Cargo and Composer read them |
| Pub | `^1.2.3` |
| RubyGems, Hex, Terraform | `~>7.1` |
| Maven, Gradle, NuGet | Intervals, such as `[1.0,2.0)` or `(,1.0]` |

Quote the whole value when it contains spaces, for example an advisory range copied as written: `depends_on:"npm/next@>= 16.0.0, < 16.4.1"`.

vcpkg, Conan, Docker and Pulumi take only the exact version as recorded.

A version check looks at installed versions. Without a lockfile it uses a version the manifest pins exactly, a Go `require`, or a GitHub Actions tag, where `v4` counts as every 4.x release. Ranges, branches and commit pins cannot be checked.

`affected_by:` takes an advisory ID or one of its aliases, such as `affected_by:CVE-2021-44228` or a GHSA ID. Dismissed and resolved findings do not count.

Both filters use the dependencies and security findings of each repository's indexed commit. A repository that has not been analyzed or scanned yet, that cannot be checked, or whose dependencies or security findings you cannot read, is left out of the search, with or without `-`. [Search filters](https://docs.corfedo.ai/use/search/filters/#find-repositories-by-package-or-advisory) shows how the results count them.

## Options

Options apply to the whole query. Each appears at most once, outside groups, and cannot be negated.

| Option | Values | Effect |
| --- | --- | --- |
| `case:` | `yes`, `no` | `yes` matches letter case in phrases, regular expressions, `file:` and `sym:`. `no` is the default. Words are not affected. |
| `type:` | `file`, `path`, `repo`, `symbol` | What the results are. `file` is the default. |
| `patterntype:` | `keyword`, `standard`, `literal`, `regexp` | `keyword`, `standard` and `literal` make every word a phrase, so each must match as written. `regexp` makes every word a regular expression. |
| `select:` | `repo` | Returns the repositories that contain matching files |
| `count:` | A number, or `all` | Results per page, at most the number your client asks for and at most 1,000. `all` is the largest page. |
| `timeout:` | A duration up to `60s`, such as `500ms`, `30s` or `1m` | How long the search may run. Without it, 5 seconds. Longer values are shortened to 15 seconds. A search that runs out of time returns the results it has found. |

### Result types

| Type | Results |
| --- | --- |
| `type:file` | Files with their matching lines |
| `type:path` | File paths. Words, phrases and regular expressions match the path instead of the content. |
| `type:repo` | Repositories. Terms match repository names, and only repository filters may accompany them. |
| `type:symbol` | Symbol declarations, with kind and line |
| `select:repo` | Repositories that contain matching files. It works only with `type:file`. |
| `select:symbol` | The same as `type:symbol`. `select:symbol.function` is `type:symbol kind:function`. |

`type:symbol` matches symbol names:

- One word matches names that contain it.
- Several words, up to 16, match names in which every word starts a part of the name, in any order and naming style. `discount policy` matches `DiscountPolicy`, `discount_policy` and `DISCOUNT_POLICY`.
- A phrase matches names with those words in that order, in any naming style.
- A `/regex/` matches names against the regular expression.
- One `sym:` regular expression, without other words, matches names against it: `sym:Runtime kind:struct type:symbol`.

With `type:symbol` you can add `kind:`, `lang:`, one `file:` and repository filters. `OR`, `NOT`, `content:`, `-file:` and `-lang:` are not supported. `case:yes` works with one word or a regular expression only.

## Values

### Symbol kinds

`kind:` takes one of these values, in lowercase: `function`, `method`, `constructor`, `class`, `interface`, `struct`, `enum`, `variable`, `property`, `constant`, `type`, `module`, `trait`, `macro`, `resource`.

A Rust `impl` block is not a declaration, so `sym:` and `type:symbol` find the type it implements, not its `impl` blocks.

### Languages

`lang:` takes a language identifier or an alias, in any letter case. Quote a value with a space, such as `lang:"protocol buffer"`.

Identifiers: `asciidoc`, `assembly`, `autoconf`, `batch`, `c`, `clojure`, `cmake`, `cpp`, `csharp`, `css`, `d`, `dart`, `diff`, `dockerfile`, `dotenv`, `ejs`, `elixir`, `erlang`, `fsharp`, `gettext`, `gitattributes`, `go`, `gomod`, `graphql`, `groovy`, `handlebars`, `haskell`, `hcl`, `html`, `ignore`, `ini`, `java`, `javascript`, `jinja`, `json`, `julia`, `kotlin`, `latex`, `less`, `lua`, `makefile`, `markdown`, `mermaid`, `nim`, `nix`, `nunjucks`, `objective-c`, `objective-cpp`, `ocaml`, `perl`, `php`, `powershell`, `prisma`, `protobuf`, `pug`, `python`, `r`, `razor`, `restructuredtext`, `ruby`, `rust`, `sass`, `scala`, `scss`, `shell`, `sql`, `starlark`, `stylus`, `svelte`, `svg`, `swift`, `tcl`, `text`, `toml`, `typescript`, `typst`, `vue`, `xml`, `yaml`, `zig`.

| Alias | Language |
| --- | --- |
| `c#`, `cs` | `csharp` |
| `c++`, `cxx` | `cpp` |
| `golang` | `go` |
| `ts`, `tsx` | `typescript` |
| `js`, `jsx` | `javascript` |
| `py` | `python` |
| `rs` | `rust` |
| `rb` | `ruby` |
| `kt` | `kotlin` |
| `f#`, `fs` | `fsharp` |
| `objc` | `objective-c` |
| `objective-c++`, `objc++` | `objective-cpp` |
| `sh`, `bash`, `zsh` | `shell` |
| `yml` | `yaml` |
| `md` | `markdown` |
| `terraform` | `hcl` |
| `proto`, `protocol buffer` | `protobuf` |
| `docker` | `dockerfile` |
| `make` | `makefile` |
| `pwsh` | `powershell` |
| `tex` | `latex` |
| `rst` | `restructuredtext` |
| `bazel` | `starlark` |
| `ex` | `elixir` |
| `erl` | `erlang` |
| `hs` | `haskell` |
| `pl` | `perl` |
| `asm` | `assembly` |
| `plaintext` | `text` |
| `cshtml` | `razor` |
| `mmd` | `mermaid` |

## Limits

| Limit | Value |
| --- | --- |
| Query length | 1 to 16,384 characters |
| Group nesting | 16 levels |
| Repository filters | 32 per query, counting each filter in a group. `context:global`, alone or in a group, counts none. |
| `repo:` patterns and repository names | 32 per search |
| `repo:` pattern length | 1 to 256 characters |
| Phrase or `lang:` value | 1,024 UTF-8 bytes |
| Regular expression, `file:` or `sym:` value | 256 UTF-8 bytes |
| All terms together | 65,536 UTF-8 bytes |
| `org:` value | 512 characters |
| `context:` name | 200 characters |
| Saved contexts in one search | 32 |
| Repositories in one search | 10,000. Narrow the filters when more match. |
| Words with `type:symbol` | 1 to 16 |
| `count:` | 1 to 1,000 results per page, and at most the page size your client asks for |
| `timeout:` | `60s` is accepted, but a search runs at most 15 seconds |

## Errors

A query that does not parse fails with `invalid_argument` and a message that names the problem, for example an unclosed group, an unknown language or a filter without a value. Nothing is searched. A regular expression that is not valid or too complex fails the same way, also in `type:symbol` and when finding usages.

These Sourcegraph filters are recognized and rejected by name, because Corfedo searches the indexed commit of each repository and stores no commit history: `rev:`, `revision:`, `branch:`, `b:`, `repo:…@revision`, `author:`, `committer:`, `before:`, `after:`, `message:`, `msg:`. `type:diff`, `type:commit`, `select:` values other than `repo`, and `repo:has.…` and `file:has.…` predicates are rejected too. To search for such text, quote it: `"rev:main"`.

Other words with a colon are ordinary text. `System::Console`, `https://host:443/x` and `foo:` search for that text.

## Differences from Sourcegraph

- Bare words are ranked by relevance, and a file needs only one of them. Join words with `AND`, or add `patterntype:keyword`, to require each one.
- Lowercase `and`, `or` and `not` between words are words. Use uppercase `OR` for the operator, as in `lang:go (timeout OR deadline)`.
- Only double quotes make a phrase. Single quotes are ordinary characters.
- Repository filters apply to the whole query. They can form one group joined by `or`, but cannot appear in a group with search terms, or beside a top-level `OR` anywhere but its start or end.
- `case:` applies to the whole query, not to one group.
- One-letter aliases are lowercase only.
- Archived repositories and forks are included by default.
- No revision, branch, diff or commit search.
- `count:` cannot raise the page size above what the client asks for, and results come in pages.
- `org:` is an exact owner, not a regular expression.
- `sym:`, `kind:`, `org:`, `depends_on:` and `affected_by:` are Corfedo filters.
- Corfedo has no `field` or `enum-member` kind: indexed fields are `variable` or `constant`, and enum members are `constant`.

## Related

- [Search your code](https://docs.corfedo.ai/use/search/) in the browser.
- [Search filters and examples](https://docs.corfedo.ai/use/search/filters/) show the syntax by task.
- [MCP tools](https://docs.corfedo.ai/connect/mcp/tools/) and [search and read with the CLI](https://docs.corfedo.ai/connect/cli/search-and-read/) use this syntax.
