You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/features/search/syntax-reference.mdx
+31-12Lines changed: 31 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,32 +4,51 @@ title: Writing search queries
4
4
5
5
Sourcebot uses a powerful regex-based query language that enabled precise code search within large codebases.
6
6
7
-
8
7
## Syntax reference guide
9
8
10
-
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.
9
+
Queries consist of space-separated search patterns that are matched against file contents. A file must have at least one match for each expression to be included. Queries can optionally contain search filters to further refine the search results.
10
+
11
+
## Keyword search (default)
12
+
13
+
Keyword search matches search patterns exactly in file contents. Wrapping search patterns in `""` combines them as a single expression.
11
14
12
15
| Example | Explanation |
13
16
| :--- | :--- |
14
-
|`foo`| Match files with regex `/foo/`|
15
-
|`foo bar`| Match files with regex `/foo/`**and**`/bar/`|
16
-
|`"foo bar"`| Match files with regex `/foo bar/`|
17
+
|`foo`| Match files containing the keyword `foo`|
18
+
|`foo bar`| Match files containing both `foo`**and**`bar`|
19
+
|`"foo bar"`| Match files containing the phrase `foo bar`|
Multiple expressions can be or'd together with `or`, negated with `-`, or grouped with `()`.
24
+
Toggle the regex button (`.*`) in the search bar to interpret search patterns as regular expressions.
19
25
20
26
| Example | Explanation |
21
27
| :--- | :--- |
22
-
|`foo or bar`| Match files with regex `/foo/`**or**`/bar/`|
23
-
|`foo -bar`| Match files with regex `/foo/` but **not**`/bar/`|
24
-
|`foo (bar or baz)`| Match files with regex `/foo/`**and** either `/bar/`**or**`/baz/`|
28
+
|`foo`| Match files with regex `/foo/`|
29
+
|`foo.*bar`| Match files with regex `/foo.*bar/` (foo followed by any characters, then bar) |
30
+
|`^function\s+\w+`| Match files with regex `/^function\s+\w+/` (function at start of line, followed by whitespace and word characters) |
31
+
|`"foo bar"`| Match files with regex `/foo bar/`. Quotes are not matched. |
25
32
26
-
Expressions can be prefixed with certain keywords to modify search behavior. Some keywords can be negated using the `-` prefix.
33
+
## Search filters
34
+
35
+
Search queries (keyword or regex) can include multiple search filters to further refine the search results. Some filters can be negated using the `-` prefix.
27
36
28
37
| Prefix | Description | Example |
29
38
| :--- | :--- | :--- |
30
39
|`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$/`|
31
-
|`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\/.*`|
40
+
|`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\/.*/`|
32
41
|`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/`|
33
42
|`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 |
34
43
|`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/`|
35
-
|`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 |
44
+
|`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 |
45
+
46
+
## Boolean operators & grouping
47
+
48
+
By default, space-separated expressions are and'd together. Using the `or` keyword as well as parentheses `()` can be used to create more complex boolean logic. Parentheses can be negated using the `-` prefix.
49
+
50
+
| Example | Explanation |
51
+
| :--- | :--- |
52
+
|`foo or bar`| Match files containing `foo`**or**`bar`|
53
+
|`foo (bar or baz)`| Match files containing `foo`**and** either `bar`**or**`baz`. |
54
+
|`-(foo) bar`| Match files containing `bar`**and not**`foo`. |
Queries consist of space-seperated regular expressions. Wrapping expressions in <CodeSnippet>{`""`}</CodeSnippet> combines them. By default, a file must have at least one match for each expression to be included.
70
+
Queries consist of space-separated search patterns that are matched against file contents. A file must have at least one match for each expression to be included. Queries can optionally contain search filters to further refine the search results.
<TableCellclassName="py-2">Match files with regex <CodeSnippet>/foo bar/</CodeSnippet></TableCell>
91
-
</TableRow>
92
-
</TableBody>
93
-
</Table>
94
73
95
-
<SeparatorclassName="my-2"/>
96
-
<pclassName="text-sm">
97
-
{`Multiple expressions can be or'd together with `}<CodeSnippet>or</CodeSnippet>, negated with <CodeSnippet>-</CodeSnippet>, or grouped with <CodeSnippet>()</CodeSnippet>.
<TableCellclassName="py-2">Match files with regex <CodeSnippet>/foo/</CodeSnippet><b>and</b> either <CodeSnippet>/bar/</CodeSnippet><b>or</b><CodeSnippet>/baz/</CodeSnippet></TableCell>
Keyword search matches search patterns exactly in file contents. Wrapping search patterns in <CodeSnippet>{`""`}</CodeSnippet> combines them as a single expression.
<TableCellclassName="py-2">Match files with regex <CodeSnippet>/^function\s+\w+/</CodeSnippet> (function at start of line, followed by whitespace and word characters)</TableCell>
<TableCellclassName="py-2">Match files with regex <CodeSnippet>/foo bar/</CodeSnippet>. Quotes are not matched.</TableCell>
137
+
</TableRow>
138
+
</TableBody>
139
+
</Table>
140
+
</div>
121
141
122
-
<SeparatorclassName="my-2"/>
123
-
<pclassName="text-sm">
124
-
Expressions can be prefixed with certain keywords to modify search behavior. Some keywords can be negated using the <CodeSnippet>-</CodeSnippet> prefix.
Search queries (keyword or regex) can include multiple search filters to further refine the search results. Some filters can be negated using the <CodeSnippet>-</CodeSnippet> prefix.
<h3className="text-lg font-semibold mt-4 mb-0">Boolean operators & grouping</h3>
252
+
<pclassName="text-sm mb-2 mt-0">
253
+
By default, space-seperated expressions are and'd together. Using the <CodeSnippet>or</CodeSnippet> keyword as well as parantheses <CodeSnippet>()</CodeSnippet> can be used to create more complex boolean logic. Parantheses can be negated using the <CodeSnippet>-</CodeSnippet> prefix.
0 commit comments