search makes a single-page REST search request for code, commits, issues, prs, or repos, and returns the link header from response for further pagination calls. If the link header is not set on the response, empty string is returned. The result argument is populated with the following information:
(query Query, result any)
| 206 | // |
| 207 | // For more information, see https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28. |
| 208 | func (s searcher) search(query Query, result any) (string, error) { |
| 209 | u, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(s.host), "search", string(query.Kind)) |
| 210 | if err != nil { |
| 211 | return "", err |
| 212 | } |
| 213 | u.SetQuery("page", strconv.Itoa(query.Page)) |
| 214 | u.SetQuery("per_page", strconv.Itoa(query.Limit)) |
| 215 | |
| 216 | if query.Kind == KindIssues { |
| 217 | // TODO advancedIssueSearchCleanup |
| 218 | // We won't need feature detection when GHES 3.17 support ends, since |
| 219 | // the advanced issue search is the only available search backend for |
| 220 | // issues. |
| 221 | features, err := s.detector.SearchFeatures() |
| 222 | if err != nil { |
| 223 | return "", err |
| 224 | } |
| 225 | |
| 226 | if !features.AdvancedIssueSearchAPI { |
| 227 | u.SetQuery("q", query.StandardSearchString()) |
| 228 | } else { |
| 229 | u.SetQuery("q", query.AdvancedIssueSearchString()) |
| 230 | |
| 231 | // TODO advancedIssueSearchCleanup |
| 232 | if features.AdvancedIssueSearchAPIOptIn { |
| 233 | // Advanced syntax should be explicitly enabled |
| 234 | u.SetQuery("advanced_search", "true") |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | switch query.IssueSearchType { |
| 239 | case "semantic": |
| 240 | if !features.SemanticSearch { |
| 241 | return "", fmt.Errorf("semantic search is not supported on this host: %s", s.host) |
| 242 | } |
| 243 | u.SetQuery("search_type", query.IssueSearchType) |
| 244 | case "hybrid": |
| 245 | if !features.HybridSearch { |
| 246 | return "", fmt.Errorf("hybrid search is not supported on this host: %s", s.host) |
| 247 | } |
| 248 | u.SetQuery("search_type", query.IssueSearchType) |
| 249 | } |
| 250 | } else { |
| 251 | u.SetQuery("q", query.StandardSearchString()) |
| 252 | } |
| 253 | |
| 254 | if query.Order != "" { |
| 255 | u.SetQuery(orderKey, query.Order) |
| 256 | } |
| 257 | if query.Sort != "" { |
| 258 | u.SetQuery(sortKey, query.Sort) |
| 259 | } |
| 260 | req, err := http.NewRequest("GET", u.String(), nil) |
| 261 | if err != nil { |
| 262 | return "", err |
| 263 | } |
| 264 | req.Header.Set("Content-Type", "application/json; charset=utf-8") |
| 265 | req.Header.Set("Accept", "application/vnd.github.v3+json") |
no test coverage detected