Help us learn about your current experience with the documentation. Take the survey.

高级搜索

  • Tier: Premium, Ultimate
  • Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated

使用高级搜索在整个 GitLab 实例中精确找到您需要的内容。

借助高级搜索,您可以:

  • 在所有项目中识别代码模式,以便更高效地重构共享组件。
  • 使用 高级漏洞管理 在整个组织的代码库和依赖项中定位安全漏洞。
  • 跟踪所有仓库中已弃用函数或库的使用情况。
  • 在议题、合并请求或评论中找到深藏的讨论。
  • 发现现有的解决方案,而不是重新发明已经存在的功能。

高级搜索适用于项目、议题、合并请求、里程碑、用户、史诗、代码、评论、提交和 Wiki。

使用高级搜索

前提条件:

要使用高级搜索:

  1. 在左侧边栏,选择 搜索或跳转至
  2. 在搜索框中,输入您的搜索词。

您也可以在项目或群组中使用高级搜索。

可用范围

范围描述了您正在搜索的数据类型。 高级搜索支持以下范围:

范围 全局 1 2 群组 项目
代码 check-circle-filled Yes check-circle-filled Yes check-circle-filled Yes
评论 check-circle-filled Yes check-circle-filled Yes check-circle-filled Yes
提交 check-circle-filled Yes check-circle-filled Yes check-circle-filled Yes
史诗 check-circle-filled Yes check-circle-filled Yes dash-circle No
议题 check-circle-filled Yes check-circle-filled Yes check-circle-filled Yes
合并请求 check-circle-filled Yes check-circle-filled Yes check-circle-filled Yes
里程碑 check-circle-filled Yes check-circle-filled Yes check-circle-filled Yes
项目 check-circle-filled Yes check-circle-filled Yes dash-circle No
用户 check-circle-filled Yes check-circle-filled Yes check-circle-filled Yes
Wiki check-circle-filled Yes check-circle-filled Yes check-circle-filled Yes

脚注:

  1. 管理员可以 禁用全局搜索范围。 在 GitLab Self-Managed 中,默认启用有限索引时,全局搜索不可用。 管理员可以 为有限索引启用全局搜索
  2. 在 GitLab.com 上,全局搜索不适用于代码、提交和 Wiki。

语法

高级搜索使用 simple_query_string, 它支持精确查询和模糊查询。

当您搜索用户时,默认使用 fuzzy 查询。 您可以使用 simple_query_string 来优化用户搜索。

语法 描述 示例
" 精确搜索 "gem sidekiq"
~ 模糊搜索 J~ Doe
| display | banner
+ display +banner
- 排除 display -banner
* 部分匹配 bug error 50*
\ 转义 \*md
# 议题 ID #23456
! 合并请求 ID !23456

代码搜索

语法 描述 示例
filename: 文件名 filename:*spec.rb
path: 仓库位置(完全或部分匹配) path:spec/workers/
extension: 文件扩展名(不含 .,仅精确匹配) extension:js
blob: Git 对象 ID(仅精确匹配) blob:998707*

示例

查询 描述
rails -filename:gemfile.lock 返回所有文件中的 rails,但 gemfile.lock 文件除外。
RSpec.describe Resolvers -*builder 返回不以 builder 开头的 RSpec.describe Resolvers
bug | (display +banner) 返回 bug,或者同时返回 displaybanner
helper -extension:yml -extension:js 返回所有文件中的 helper,但扩展名为 .yml.js 的文件除外。
helper path:lib/git 返回所有路径为 lib/git* 的文件中的 helper(例如 spec/lib/gitlab)。

已知问题

  • 只能搜索小于 1 MB 的文件。 有关更多信息,请参阅 issue 195764。 对于 GitLab Self-Managed,管理员可以 配置 最大索引文件大小 设置

  • 您只能在项目的默认分支上使用高级搜索。 有关更多信息,请参阅 issue 229966

  • 搜索查询不能包含以下任何字符:

    . , : ; / ` ' = ? $ & ^ | < > ( ) { } [ ] @

    有关更多信息,请参阅 issue 325234

  • 搜索结果只显示文件中的第一个匹配项。 有关更多信息,请参阅 issue 668