文章版本: Enterprise Server 2.17
了解搜索语法
搜索 GitHub Enterprise 时,您可以构建匹配特定数字和单词的查询。
查询大于或小于另一个值的值
您可以使用 >、>=、< 和 <= 搜索大于、大于等于、小于以及小于等于另一个值的值。
| 查询 | 示例 | 
|---|---|
| >n | cats stars:>1000 matches repositories with the word "cats" that have more than 1000 stars. | 
| >=n | cats topics:>=5 matches repositories with the word "cats" that have 5 or more topics. | 
| <n | cats size:<10000 matches code with the word "cats" in files that are smaller than 10 KB. | 
| <=n | cats stars:<=50 matches repositories with the word "cats" that have 50 or fewer stars. | 
您还可以使用范围查询搜索大于等于或小于等于另一个值的值。
| 查询 | 示例 | 
|---|---|
| n..* | cats stars:10..* 等同于 stars:>=10并匹配含有 "cats" 字样、有 10 个或更多星号的仓库。 | 
| *..n | cats stars:*..10 等同于 stars:<=10并匹配含有 "cats" 字样、有不超过 10 个星号的仓库。 | 
查询范围之间的值
You can use the range syntax n..n to search for values within a range, where the first number n is the lowest value and the second is the highest value.
| 查询 | 示例 | 
|---|---|
| n..n | cats stars:10..50 匹配含有 "cats" 字样、有 10 到 50 个星号的仓库。 | 
查询日期
您可以通过使用 >、>=、<、<= 和范围查询搜索早于或晚于另一个日期,或者位于日期范围内的日期。 日期格式必须遵循 ISO8601标准,即 YYYY-MM-DD(年-月-日)。
| 查询 | 示例 | 
|---|---|
| >YYYY-MM-DD | cats created:>2016-04-29 matches issues with the word "cats" that were created after April 29, 2016. | 
| >=YYYY-MM-DD | cats created:>=2017-04-01 matches issues with the word "cats" that were created on or after April 1, 2017. | 
| <YYYY-MM-DD | cats pushed:<2012-07-05 matches code with the word "cats" in repositories that were pushed to before July 5, 2012. | 
| <=YYYY-MM-DD | cats created:<=2012-07-04 matches issues with the word "cats" that were created on or before July 4, 2012. | 
| YYYY-MM-DD..YYYY-MM-DD | cats pushed:2016-04-30..2016-07-04 匹配含有 "cats" 字样、在 2016 年 4 月末到 7 月之间推送的仓库。 | 
| YYYY-MM-DD..* | cats created:2012-04-30..* 匹配在 2012 年 4 月 30 日之后创建、含有 "cats" 字样的议题。 | 
| *..YYYY-MM-DD | cats created:*..2012-04-30 匹配在 2012 年 7 月 4 日之前创建、含有 "cats" 字样的议题。 | 
您也可以在日期后添加可选的时间信息 THH:MM:SS+00:00,以便按小时、分钟和秒进行搜索。 这是 T,随后是 HH:MM:SS(时-分-秒)和 UTC 偏移 (+00:00)。
| 查询 | 示例 | 
|---|---|
| YYYY-MM-DDTHH:MM:SS+00:00 | cats created:2017-01-01T01:00:00+07:00..2017-03-01T15:30:15+07:00 匹配在 2017 年 1 月 1 日凌晨 1 点(UTC 偏移为 07:00)与 2017 年 3 月 1 日下午 3 点(UTC 偏移为07:00)之间创建的议题。 | 
| YYYY-MM-DDTHH:MM:SSZ | cats created:2016-03-21T14:11:00Z..2016-04-07T20:45:00Z 匹配在 2016 年 3 月 21 日下午 2:11 与 2016 年 4 月 7 日晚上 8:45 之间创建的议题。 | 
排除特定结果
您可以使用 NOT 语法排除包含特定字词的结果。 NOT 运算符只能用于字符串关键词, 不适用于数字或日期。
| 查询 | 示例 | 
|---|---|
| NOT | hello NOT world 匹配含有 "hello" 字样但不含有 "world" 字样的仓库。 | 
缩小搜索结果范围的另一种途径是排除特定的子集。 您可以为任何搜索限定符添加 - 前缀,以排除该限定符匹配的所有结果。
| 查询 | 示例 | 
|---|---|
| -QUALIFIER | cats stars:>10 -language:javascript matches repositories with the word "cats" that have more than 10 stars but are not written in JavaScript. | 
| mentions:defunkt -org:github 匹配提及 @defunkt 且不在 GitHub 组织仓库中的议题 | 
对带有空格的查询使用引号
如果搜索含有空格的查询,您需要用引号将其括起来。 例如:
- cats NOT "hello world" 匹配含有 "cats" 字样但不含有 "hello world" 字样的仓库。
- build label:"bug fix" 匹配具有标签 "bug fix"、含有 "build" 字样的议题。
某些非字母数字符号(例如空格)会从引号内的代码搜索查询中删除,因此结果可能出乎意料。