doc/user/search/exact_code_search.md
{{< details >}}
{{< /details >}}
{{< history >}}
index_code_with_zoekt and search_code_with_zoekt. Disabled by default.zoekt_cross_namespace_search. Disabled by default.index_code_with_zoekt and search_code_with_zoekt removed in GitLab 17.1.zoekt_cross_namespace_search removed in GitLab 18.7.{{< /history >}}
[!warning] This feature is in limited availability. For more information, see epic 9404. Provide feedback in issue 420920.
With exact code search, you can use exact match and regular expression modes to search for code in all GitLab or in a specific project.
Exact code search is powered by Zoekt and is used by default in groups where the feature is enabled.
Prerequisites:
To use exact code search:
You can also use exact code search in a project or group.
Scopes describe the type of data you're searching. The following scopes are available for exact code search:
| Scope | Global <sup>1</sup> <sup>2</sup> | Group | Project |
|---|---|---|---|
| Code | {{< no >}} | {{< yes >}} | {{< yes >}} |
Footnotes:
zoekt_cross_namespace_search feature flag.{{< history >}}
zoekt_search_api. Enabled by default.zoekt_search_api removed.{{< /history >}}
With the Zoekt search API, you can use the search API for exact code search. To use advanced search or basic search instead, specify a search type.
{{< history >}}
zoekt_exact_search. Disabled by default.zoekt_exact_search removed.{{< /history >}}
GitLab has two search modes:
The exact match mode is used by default. To switch to the regular expression mode, to the right of the search box, select Use regular expression ({{< icon name="regular-expression" >}}).
This table shows some example queries for exact match and regular expression modes.
| Query | Exact match mode | Regular expression mode |
|---|---|---|
"foo" | "foo" | foo |
foo file:^doc/ | foo in directories that start with /doc | foo in directories that start with /doc |
"class foo" | "class foo" | class foo |
class foo | class foo | class and foo |
foo or bar | foo or bar | foo or bar |
class Foo | class Foo (case-sensitive) | class (case-insensitive) and Foo (case-sensitive) |
class Foo case:yes | class Foo (case-sensitive) | class and Foo (both case-sensitive) |
foo -bar | foo -bar | foo but not bar |
foo file:js | foo in files with names that contain js | foo in files with names that contain js |
foo -file:test | foo in files with names that do not contain test | foo in files with names that do not contain test |
foo lang:ruby | foo in Ruby source code | foo in Ruby source code |
foo file:\.js$ | foo in files with names that end with .js | foo in files with names that end with .js |
foo.*bar | foo.*bar (literal) | foo.*bar (regular expression) |
sym:foo | foo in symbols like class, method, and variable names | foo in symbols like class, method, and variable names |
test repo:(?i)foo | test in projects with foo in their name (case-insensitive); repo: supports regular expressions | test in projects with foo in their name (case-insensitive); repo: supports regular expressions |
20_000 trigrams.
For more information, see issue 455073.gitlab-zoekt to version 1.5.0 or later.