Exact code search
- Tier: Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed
- Status: Beta
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.
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.
In user preferences, you can disable exact code search to use advanced search instead.
Zoekt search API
The availability of this feature is controlled by a feature flag. For more information, see the history. This feature is available for testing, but not ready for production use.
With the Zoekt search API, you can use the search API for exact code search. If you want to use advanced search or basic search instead, see specify a search type.
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
The availability of this feature is controlled by a feature flag. For more information, see the history. This feature is available for testing, but not ready for production use.
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
GitLab has two search modes:
- Exact match mode: returns results that exactly match the query.
- Regular expression mode: supports regular and boolean expressions.
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 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 |
Known issues
- You can only search files smaller than 1 MB with less than
20_000
trigrams. For more information, see issue 455073. - You can use exact code search on the default branch of a project only. For more information, see issue 403307.
- Multiple matches on a single line are counted as one result. For more information, see issue 514526.
- If you encounter results where newlines are not displayed correctly,
you must update
gitlab-zoekt
to version 1.5.0 or later. For more information, see issue 516937.
Docs
Edit this page to fix an error or add an improvement in a merge request.
Create an issue to suggest an improvement to this page.
Product
Create an issue if there's something you don't like about this feature.
Propose functionality by submitting a feature request.
Feature availability and product trials
View pricing to see all GitLab tiers and features, or to upgrade.
Try GitLab for free with access to all features for 30 days.
Get help
If you didn't find what you were looking for, search the docs.
If you want help with something specific and could use community support, post on the GitLab forum.
For problems setting up or using this feature (depending on your GitLab subscription).
Request support