如何使用 GitHub 搜索 API 在 GitHub 分支中搜索代码?
How to search a GitHub fork for code using the GitHub Search API?
我不知道如何从 GitHub 存储库的分支中获取搜索结果。
我为此使用 GitHub API,但我可以使用 github.com 上的搜索对话框重现该问题。这是一个示例:存储库 PEZ/Sketch-Plugin-Testing-Repo is a fork of getflourish/Sketch-Mate. They both contain a manifest.json
file with several mentions of the word shortcut
. The GitHub Code Search documentation 说:
Much like with repositories, you can opt to search code files that exist within forked repositories. However, to ensure better relevancy, repository forks will not be searchable unless the fork has more stars than the parent repository.
If you would like forked results to appear, add the fork:true qualifier. For example:
android language:java fork:true
Matches code in a forked repository with the word "android" that's written in Java.
因此,对 shortcut in:file filename:manifest.json repo:PEZ/Sketch-Plugin-Testing-Repo repo:getflourish/Sketch-Mate fork:true 的搜索应该 return 来自两个存储库。 但它根本不包含任何搜索结果。
省略 fork:true 限定符 - shortcut in:file filename:manifest.json repo:PEZ/Sketch-Plugin-Testing-Repo repo:getflourish/Sketch-Mate,我们确实从原始(非分叉)存储库中获取搜索结果。
我哪里不明白?
为了让事情更神秘一点,请考虑存储库 repo:TeamTwisted/external_chromium_org which is a fork of OptiPop/external_chromium_org。这两个存储库还包含 manifest.json
个包含单词 shortcut
.
的文件
从所有存储库中搜索 shortcut in:file filename:manifest.json repo:PEZ/Sketch-Plugin-Testing-Repo repo:getflourish/Sketch-Mate repo:TeamTwisted/external_chromium_org repo:OptiPop/external_chromium_org fork:true, includes results only from the TeamTwisted/external_chromium_org
repository. While omitting the fork:true 限定符 return 结果 除了 PEZ/Sketch-Plugin-Testing-Repo
.
有人知道发生了什么事吗? PEZ/Sketch-Plugin-Testing-Repo
是否由于某种原因完全无法搜索?我的测试库唯一特别之处在于它是一个新制作的叉子。也许我在 11 月 8 日或类似的时候(两天前在撰写本文时)将其分叉。
理想情况下,我想使用一个搜索查询并从一组给定的存储库中获取结果,无论它们是否是分叉。但始终如一地从分叉中获得结果将是一个好的开始...
你也联系了 GitHub 支持人员,所以我想在这里分享你从 Jess 那里得到的答案,以防有帮助。
When a fork has less stars than its parent, it is not indexed at all for code search. So it won't show up even when you use fork:true. The fork:true search filter is used to show results for forks that have been indexed for search.
In the example of the TeamTwisted/external_chromium_org fork, that code is searchable because it has more stars than its parent repo. However the PEZ/Sketch-Plugin-Testing-Repo fork does not, so it won't be searchable at all with any filter.
我不知道如何从 GitHub 存储库的分支中获取搜索结果。
我为此使用 GitHub API,但我可以使用 github.com 上的搜索对话框重现该问题。这是一个示例:存储库 PEZ/Sketch-Plugin-Testing-Repo is a fork of getflourish/Sketch-Mate. They both contain a manifest.json
file with several mentions of the word shortcut
. The GitHub Code Search documentation 说:
Much like with repositories, you can opt to search code files that exist within forked repositories. However, to ensure better relevancy, repository forks will not be searchable unless the fork has more stars than the parent repository.
If you would like forked results to appear, add the fork:true qualifier. For example:
android language:java fork:true Matches code in a forked repository with the word "android" that's written in Java.
因此,对 shortcut in:file filename:manifest.json repo:PEZ/Sketch-Plugin-Testing-Repo repo:getflourish/Sketch-Mate fork:true 的搜索应该 return 来自两个存储库。 但它根本不包含任何搜索结果。
省略 fork:true 限定符 - shortcut in:file filename:manifest.json repo:PEZ/Sketch-Plugin-Testing-Repo repo:getflourish/Sketch-Mate,我们确实从原始(非分叉)存储库中获取搜索结果。
我哪里不明白?
为了让事情更神秘一点,请考虑存储库 repo:TeamTwisted/external_chromium_org which is a fork of OptiPop/external_chromium_org。这两个存储库还包含 manifest.json
个包含单词 shortcut
.
从所有存储库中搜索 shortcut in:file filename:manifest.json repo:PEZ/Sketch-Plugin-Testing-Repo repo:getflourish/Sketch-Mate repo:TeamTwisted/external_chromium_org repo:OptiPop/external_chromium_org fork:true, includes results only from the TeamTwisted/external_chromium_org
repository. While omitting the fork:true 限定符 return 结果 除了 PEZ/Sketch-Plugin-Testing-Repo
.
有人知道发生了什么事吗? PEZ/Sketch-Plugin-Testing-Repo
是否由于某种原因完全无法搜索?我的测试库唯一特别之处在于它是一个新制作的叉子。也许我在 11 月 8 日或类似的时候(两天前在撰写本文时)将其分叉。
理想情况下,我想使用一个搜索查询并从一组给定的存储库中获取结果,无论它们是否是分叉。但始终如一地从分叉中获得结果将是一个好的开始...
你也联系了 GitHub 支持人员,所以我想在这里分享你从 Jess 那里得到的答案,以防有帮助。
When a fork has less stars than its parent, it is not indexed at all for code search. So it won't show up even when you use fork:true. The fork:true search filter is used to show results for forks that have been indexed for search.
In the example of the TeamTwisted/external_chromium_org fork, that code is searchable because it has more stars than its parent repo. However the PEZ/Sketch-Plugin-Testing-Repo fork does not, so it won't be searchable at all with any filter.