Exact code search
-
Introduced as a beta in GitLab 15.9 with flags named
index_code_with_zoekt
andsearch_code_with_zoekt
. Disabled by default. - Enabled on GitLab.com in GitLab 16.6.
- Feature flags
index_code_with_zoekt
andsearch_code_with_zoekt
removed in GitLab 17.1.
With exact code search, you can use regular expression and exact match 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.
Enable exact code search
- For GitLab.com, exact code search is enabled in paid subscriptions.
- For GitLab self-managed, an administrator must install Zoekt and enable exact code search.
Zoekt search API
-
Introduced in GitLab 16.9 with a flag named
zoekt_search_api
. Enabled by default.
With the Zoekt search API, you can use the search API for exact code search. When this feature is disabled, advanced search or basic search is used instead.
By default, the Zoekt search API is disabled on GitLab.com to avoid breaking changes. To request access to this feature, contact GitLab.
Global code search
-
Introduced in GitLab 16.11 with a flag named
zoekt_cross_namespace_search
. Disabled by default.
Use this feature to search code across the entire GitLab instance.
Global code search does not perform well on large GitLab instances. When this feature is enabled for instances with more than 20,000 projects, your search might time out.
Search modes
-
Introduced in GitLab 16.8 with a flag named
zoekt_exact_search
. Disabled by default. -
Generally available in GitLab 17.3. Feature flag
zoekt_exact_search
removed.
GitLab has two search modes:
- Regular expression mode: supports regular and boolean expressions.
- Exact match mode: returns results that exactly match the query.
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 ().
Syntax
This table shows some example queries for regular expression and exact match modes.
Query | Regular expression mode | Exact match 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 and foo
| class foo
|
foo or bar
|
foo or bar
| foo or bar
|
class Foo
|
class (case insensitive) and Foo (case sensitive)
|
class Foo (case insensitive)
|
class Foo case:yes
|
class and Foo (both case sensitive)
|
class Foo (case sensitive)
|
foo -bar
|
foo but not bar
| foo -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 (regular expression)
| None |
sym:foo
|
foo in symbols like class, method, and variable names
|
foo in symbols like class, method, and variable names
|