* testing out a rest operations sidebar * cleanup * renamed 5 files * renamed 5 files * set redirect_from on 5 files * renamed 1 files * renamed 1 files * renamed 3 files * renamed 1 files * renamed 1 files * renamed 3 files * renamed 1 files * renamed 2 files * renamed 1 files * renamed 4 files * renamed 15 files * renamed 2 files * renamed 6 files * renamed 1 files * renamed 4 files * renamed 7 files * renamed 1 files * renamed 3 files * renamed 3 files * renamed 1 files * renamed 5 files * renamed 1 files * renamed 1 files * renamed 3 files * renamed 4 files * renamed 1 files * renamed 1 files * renamed 2 files * renamed 4 files * renamed 1 files * renamed 1 files * renamed 1 files * renamed 6 files * renamed 6 files * renamed 4 files * move files * adding more * updating to add restcontext and start of removing data/reusables/rest-reference * removed data/reusables * add a RestMiniTocItem and updating the filtering to add a subcategory so all manually added H3s are in mini tocs in addition to operations * remove console log * [WIP]: REST New Proposal Sidebar (#26471) * saving * update sidebar * remove console log * update guides and overview * import Category for category level rest pages * update undefined restOperations * update restOperationData category and subcategory levels" * minor updates * update get mini toc items function * updating REST context for sidebar * updating rest data * remove console logs * WIP: mini-toc-ing the sidebar Co-authored-by: Robert Sese <rsese@github.com> * A little cleanup * Fix first subcategory link and add some comments * updating anchor links in sidebar * adding updates * remove standalone * update product and maptopic pages using article context * add conditional link wrapper * fix sidebar toggle and versions for enterprise admin * update versions per subcategory * Highlight sidebar link for current page * Update miniToc hash links and hash change tracking * fix unique key in CollapsibleSection * Fix list markup * remove title * update permissions * Hide minitocs on landing (#26594) * hide minitocs on landing page * simplify page components and remove minitoc from sidebar for guides/overview * fix carats and category fix * remove id Co-authored-by: Grace Park <gracepark@github.com> * updating content based on versions script check with the OpenAPI * update script and content files * update script and content/rest files * update to add TocLanding * update script * update index files * add codespaces repository-secrets * remove openapi schema check script * remove minitocs at the top * add h2 about the {title} api * fix tests/unit/openapi-schema.js * Fix linting tests * fix search/topics test * fix tests/unit/pages test * update rest/reference links in components * run prettier * Update components/rest/RestReferencePage.tsx Co-authored-by: Rachael Sewell <rachmari@github.com> * Update components/rest/RestReferencePage.tsx Co-authored-by: Rachael Sewell <rachmari@github.com> * Update pages/[versionId]/rest/[category]/[subcategory].tsx Co-authored-by: Rachael Sewell <rachmari@github.com> * Update pages/[versionId]/rest/[category]/[subcategory].tsx Co-authored-by: Rachael Sewell <rachmari@github.com> * Update pages/[versionId]/rest/[category]/[subcategory].tsx Co-authored-by: Rachael Sewell <rachmari@github.com> * Update pages/[versionId]/rest/[category]/[subcategory].tsx Co-authored-by: Rachael Sewell <rachmari@github.com> * Update tests/unit/openapi-schema.js Co-authored-by: Rachael Sewell <rachmari@github.com> * updating comment location * remove dependabot override * remove path-utils current product update for rest * run linter * remove dependabot.md and remove h2 heading on restreference * update the correct product to rest for rest pages * adding comments for updates to path-utils * remove console log * REST sidebar: handle legacy v3 redirects (#26686) * Add script to handle legacy v3 REST redirects * Run the script * Handle a redirect to a redirect * Update REST test URLs * 'await' and test runs subcategory of checks * Update REST URLs for routing/developer-site-redirects tests * Update developer-redirects fixture with new REST URLs * Resolve merge conflicts * Update rest-redirects fixture with new REST URLs * Fix broken links with REST pages re-org * redirectTo could be undefined * Fix script for posterity, can't redirect paths with hashes * Remove invalid hash redirects * Typically don't need to save one-off scripts * Undo redirect changes (not necessary for handling v3 redirects) * Remove script-added redirects * Update old v3 redirects with new REST URLs * No more GHES search indexing page * 'org' not 'organization' * Update fixture data for new REST URLs * revert any content directory changes Co-authored-by: Grace Park <gracepark@github.com> Co-authored-by: Rachael Sewell <rachmari@github.com> * Adding test rest (#26750) * add test to check openapi schema versions and content rest frontmatter versions * update lib/redirects * fix test and add error messages * adding repository secrets * adding repository-secrets.md * Revert "update lib/redirects" This reverts commit 3aafe28265764d5bc09c0c478c8e0ca099c8fbcf. * remove lib/redirects changes and console logs * Update lib/rest/index.js Co-authored-by: Rachael Sewell <rachmari@github.com> * update unique key * Rest client side redirects (#26754) * adding tags subcategory for the rest content repos category * run prettier * bug fix for anchor scrolls" (#26892) * updating width size for rest reference page * Rest sidebar consolidation (#26862) * refactor sidebar * fix articlecontext provider issue on rest product landing page for all versions * fix a bug, create new component * revert change to create new component and fix bug Co-authored-by: Rachael Sewell <rachmari@github.com> * Set currentAnchor with a hashchange handler (#26923) * Rest sidebar design tweaks (#26807) * Rest sidebar design tweaks * tweak color to subtle * use muted color and margin for line * update to design feedback Co-authored-by: Grace Park <gracepark@github.com> * Remove cheerio from rest-collapsible (#26948) * remove cheerio from rest-collapsible * update type * adding endswith instead * use productId instead * one off edge case for secret-scanning * Reorganize subcategory and category, Update pre -> div, Add RestContext (#26950) * reorganize subcategory and category * add RestContext * update comment * update for endpoints page * add comment * move object to restcontext * remove effectiveDate in restcontext * remove width calculation for rest reference page * fix adding manual writer's minitocs to sidebar * update with feedback * update comment * update isRestReferencePage * remove page component and fix bug * adding back rest/index.tsx Co-authored-by: Rachael Sewell <rachmari@github.com> * update content/rest" * add back design tweak * update to div * update margins on rest api reference * remove page component * adding tests * separate product from rest sidebar (#27065) * separate product from rest sidebar * Use ProductCollapsibleSections for product pages * fix tests Co-authored-by: Robert Sese <rsese@github.com> Co-authored-by: Grace Park <gracepark@github.com> * Rest sidebar translations (#27052) * update translations * remove general test Co-authored-by: Robert Sese <rsese@github.com> Co-authored-by: Rachael Sewell <rachmari@github.com>
8.8 KiB
title, intro, versions, topics, miniTocMaxHeadingLevel, redirect_from
| title | intro | versions | topics | miniTocMaxHeadingLevel | redirect_from | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Search | The GitHub Search API lets you to search for the specific item efficiently. |
|
|
3 |
|
The Search API helps you search for the specific item you want to find. For example, you can find a user or a specific file in a repository. Think of it the way you think of performing a search on Google. It's designed to help you find the one result you're looking for (or maybe the few results you're looking for). Just like searching on Google, you sometimes want to see a few pages of search results so that you can find the item that best meets your needs. To satisfy that need, the {% data variables.product.product_name %} Search API provides up to 1,000 results for each search.
You can narrow your search using queries. To learn more about the search query syntax, see "Constructing a search query."
Ranking search results
Unless another sort option is provided as a query parameter, results are sorted by best match in descending order. Multiple factors are combined to boost the most relevant item to the top of the result list.
Rate limit
{% data reusables.enterprise.rate_limit %}
The Search API has a custom rate limit. For requests using Basic Authentication, OAuth, or client ID and secret, you can make up to 30 requests per minute. For unauthenticated requests, the rate limit allows you to make up to 10 requests per minute.
See the rate limit documentation for details on determining your current rate limit status.
Constructing a search query
Each endpoint in the Search API uses query parameters to perform searches on {% data variables.product.product_name %}. See the individual endpoint in the Search API for an example that includes the endpoint and query parameters.
A query can contain any combination of search qualifiers supported on {% data variables.product.product_name %}. The format of the search query is:
SEARCH_KEYWORD_1 SEARCH_KEYWORD_N QUALIFIER_1 QUALIFIER_N
For example, if you wanted to search for all repositories owned by defunkt that
contained the word GitHub and Octocat in the README file, you would use the
following query with the search repositories endpoint:
GitHub Octocat in:readme user:defunkt
Note: Be sure to use your language's preferred HTML-encoder to construct your query strings. For example:
// JavaScript
const queryString = 'q=' + encodeURIComponent('GitHub Octocat in:readme user:defunkt');
See "Searching on GitHub" for a complete list of available qualifiers, their format, and an example of how to use them. For information about how to use operators to match specific quantities, dates, or to exclude results, see "Understanding the search syntax."
Limitations on query length
The Search API does not support queries that:
- are longer than 256 characters (not including operators or qualifiers).
- have more than five
AND,OR, orNOToperators.
These search queries will return a "Validation failed" error message.
Timeouts and incomplete results
To keep the Search API fast for everyone, we limit how long any individual query
can run. For queries that exceed the time limit,
the API returns the matches that were already found prior to the timeout, and
the response has the incomplete_results property set to true.
Reaching a timeout does not necessarily mean that search results are incomplete. More results might have been found, but also might not.
Access errors or missing search results
You need to successfully authenticate and have access to the repositories in your search queries, otherwise, you'll see a 422 Unprocessable Entry error with a "Validation Failed" message. For example, your search will fail if your query includes repo:, user:, or org: qualifiers that request resources that you don't have access to when you sign in on {% data variables.product.prodname_dotcom %}.
When your search query requests multiple resources, the response will only contain the resources that you have access to and will not provide an error message listing the resources that were not returned.
For example, if your search query searches for the octocat/test and codertocat/test repositories, but you only have access to octocat/test, your response will show search results for octocat/test and nothing for codertocat/test. This behavior mimics how search works on {% data variables.product.prodname_dotcom %}.
Text match metadata
On GitHub, you can use the context provided by code snippets and highlights in search results. The Search API offers additional metadata that allows you to highlight the matching search terms when displaying search results.
Requests can opt to receive those text fragments in the response, and every fragment is accompanied by numeric offsets identifying the exact location of each matching search term.
To get this metadata in your search results, specify the text-match media type in your Accept header.
application/vnd.github.v3.text-match+json
When you provide the text-match media type, you will receive an extra key in the JSON payload called text_matches that provides information about the position of your search terms within the text and the property that includes the search term. Inside the text_matches array, each object includes
the following attributes:
| Name | Description |
|---|---|
object_url |
The URL for the resource that contains a string property matching one of the search terms. |
object_type |
The name for the type of resource that exists at the given object_url. |
property |
The name of a property of the resource that exists at object_url. That property is a string that matches one of the search terms. (In the JSON returned from object_url, the full content for the fragment will be found in the property with this name.) |
fragment |
A subset of the value of property. This is the text fragment that matches one or more of the search terms. |
matches |
An array of one or more search terms that are present in fragment. The indices (i.e., "offsets") are relative to the fragment. (They are not relative to the full content of property.) |
Example
Using cURL, and the example issue search above, our API request would look like this:
curl -H 'Accept: application/vnd.github.v3.text-match+json' \
'{% data variables.product.api_url_pre %}/search/issues?q=windows+label:bug+language:python+state:open&sort=created&order=asc'
The response will include a text_matches array for each search result. In the JSON below, we have two objects in the text_matches array.
The first text match occurred in the body property of the issue. We see a fragment of text from the issue body. The search term (windows) appears twice within that fragment, and we have the indices for each occurrence.
The second text match occurred in the body property of one of the issue's comments. We have the URL for the issue comment. And of course, we see a fragment of text from the comment body. The search term (windows) appears once within that fragment.
{
"text_matches": [
{
"object_url": "https://api.github.com/repositories/215335/issues/132",
"object_type": "Issue",
"property": "body",
"fragment": "comprehensive windows font I know of).\n\nIf we can find a commonly distributed windows font that supports them then no problem (we can use html font tags) but otherwise the '(21)' style is probably better.\n",
"matches": [
{
"text": "windows",
"indices": [
14,
21
]
},
{
"text": "windows",
"indices": [
78,
85
]
}
]
},
{
"object_url": "https://api.github.com/repositories/215335/issues/comments/25688",
"object_type": "IssueComment",
"property": "body",
"fragment": " right after that are a bit broken IMHO :). I suppose we could have some hack that maxes out at whatever the font does...\n\nI'll check what the state of play is on Windows.\n",
"matches": [
{
"text": "Windows",
"indices": [
163,
170
]
}
]
}
]
}
