mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-15 05:45:20 +00:00
35 lines
No EOL
2.5 KiB
Text
35 lines
No EOL
2.5 KiB
Text
---
|
|
title: Writing search queries
|
|
---
|
|
|
|
Sourcebot uses a powerful regex-based query language that enabled precise code search within large codebases.
|
|
|
|
|
|
## Syntax reference guide
|
|
|
|
Queries consist of space-separated regular expressions. Wrapping expressions in `""` combines them. By default, a file must have at least one match for each expression to be included.
|
|
|
|
| Example | Explanation |
|
|
| :--- | :--- |
|
|
| `foo` | Match files with regex `/foo/` |
|
|
| `foo bar` | Match files with regex `/foo/` **and** `/bar/` |
|
|
| `"foo bar"` | Match files with regex `/foo bar/` |
|
|
|
|
Multiple expressions can be or'd together with `or`, negated with `-`, or grouped with `()`.
|
|
|
|
| Example | Explanation |
|
|
| :--- | :--- |
|
|
| `foo or bar` | Match files with regex `/foo/` **or** `/bar/` |
|
|
| `foo -bar` | Match files with regex `/foo/` but **not** `/bar/` |
|
|
| `foo (bar or baz)` | Match files with regex `/foo/` **and** either `/bar/` **or** `/baz/` |
|
|
|
|
Expressions can be prefixed with certain keywords to modify search behavior. Some keywords can be negated using the `-` prefix.
|
|
|
|
| Prefix | Description | Example |
|
|
| :--- | :--- | :--- |
|
|
| `file:` | Filter results from filepaths that match the regex. By default all files are searched. | `file:README` - Filter results to filepaths that match regex `/README/`<br/>`file:"my file"` - Filter results to filepaths that match regex `/my file/`<br/>`-file:test\.ts$` - Ignore results from filepaths match regex `/test\.ts$/` |
|
|
| `repo:` | Filter results from repos that match the regex. By default all repos are searched. | `repo:linux` - Filter results to repos that match regex `/linux/`<br/>`-repo:^web/.*` - Ignore results from repos that match regex `/^web\/.*` |
|
|
| `rev:` | Filter results from a specific branch or tag. By default **only** the default branch is searched. | `rev:beta` - Filter results to branches that match regex `/beta/` |
|
|
| `lang:` | Filter results by language (as defined by [linguist](https://github.com/github-linguist/linguist/blob/main/lib/linguist/languages.yml)). By default all languages are searched. | `lang:TypeScript` - Filter results to TypeScript files<br/>`-lang:YAML` - Ignore results from YAML files |
|
|
| `sym:` | Match symbol definitions created by [universal ctags](https://ctags.io/) at index time. | `sym:\bmain\b` - Filter results to symbols that match regex `/\bmain\b/` |
|
|
| `context:` | Filter results to a predefined [search context](/docs/features/search/search-contexts). | `context:web` - Filter results to the web context<br/>`-context:pipelines` - Ignore results from the pipelines context | |