|
|
|
@ -34,6 +34,9 @@ type SearchOptions struct { |
|
|
|
// desc. Default is desc.
|
|
|
|
Order string `url:"order,omitempty"` |
|
|
|
|
|
|
|
// Whether to retrieve text match metadata with a query
|
|
|
|
TextMatch bool `url:"-"` |
|
|
|
|
|
|
|
ListOptions |
|
|
|
} |
|
|
|
|
|
|
|
@ -82,6 +85,25 @@ func (s *SearchService) Users(query string, opt *SearchOptions) (*UsersSearchRes |
|
|
|
return result, resp, err |
|
|
|
} |
|
|
|
|
|
|
|
// Match represents a single text match.
|
|
|
|
type Match struct { |
|
|
|
Text *string `json:"text,omitempty"` |
|
|
|
Indices []int `json:"indices,omitempty"` |
|
|
|
} |
|
|
|
|
|
|
|
// TextMatch represents a text match for a SearchResult
|
|
|
|
type TextMatch struct { |
|
|
|
ObjectURL *string `json:"object_url,omitempty"` |
|
|
|
ObjectType *string `json:"object_type,omitempty"` |
|
|
|
Property *string `json:"property,omitempty"` |
|
|
|
Fragment *string `json:"fragment,omitempty"` |
|
|
|
Matches []Match `json:"matches,omitempty"` |
|
|
|
} |
|
|
|
|
|
|
|
func (tm TextMatch) String() string { |
|
|
|
return Stringify(tm) |
|
|
|
} |
|
|
|
|
|
|
|
// CodeSearchResult represents the result of an code search.
|
|
|
|
type CodeSearchResult struct { |
|
|
|
Total *int `json:"total_count,omitempty"` |
|
|
|
@ -90,11 +112,12 @@ type CodeSearchResult struct { |
|
|
|
|
|
|
|
// CodeResult represents a single search result.
|
|
|
|
type CodeResult struct { |
|
|
|
Name *string `json:"name,omitempty"` |
|
|
|
Path *string `json:"path,omitempty"` |
|
|
|
SHA *string `json:"sha,omitempty"` |
|
|
|
HTMLURL *string `json:"html_url,omitempty"` |
|
|
|
Repository *Repository `json:"repository,omitempty"` |
|
|
|
Name *string `json:"name,omitempty"` |
|
|
|
Path *string `json:"path,omitempty"` |
|
|
|
SHA *string `json:"sha,omitempty"` |
|
|
|
HTMLURL *string `json:"html_url,omitempty"` |
|
|
|
Repository *Repository `json:"repository,omitempty"` |
|
|
|
TextMatches []TextMatch `json:"text_matches,omitempty"` |
|
|
|
} |
|
|
|
|
|
|
|
func (c CodeResult) String() string { |
|
|
|
@ -125,5 +148,11 @@ func (s *SearchService) search(searchType string, query string, opt *SearchOptio |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
if opt.TextMatch { |
|
|
|
// Accept header defaults to "application/vnd.github.v3+json"
|
|
|
|
// We change it here to fetch back text-match metadata
|
|
|
|
req.Header.Set("Accept", "application/vnd.github.v3.text-match+json") |
|
|
|
} |
|
|
|
|
|
|
|
return s.client.Do(req, result) |
|
|
|
} |