codesearch

package
v0.0.0-...-e0ff526 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package codesearch wraps up the codesearch JSON API.

Notes about the codesearch REST API:

The query needs to be bracketed by search_request=[b|e] query parameters.

For example:

https://cs.chromium.org/codesearch/json/search_request:1
   ?search_request=b
   &query=file%3A.md+file%3A%5Esrc%2Fthird_party%2Fskia%2F+package%3A%5Echromium%24
   &max_num_results=20
   &results_offset=0
   &search_request=e

The URL for a file.name of "src/third_party/skia/site/roles.md" is

https://cs.chromium.org/chromium/src/third_party/skia/site/roles.md

To jump to a specific line:

https://cs.chromium.org/chromium/src/third_party/skia/site/roles.md?l=2

Index

Constants

View Source
const (

	// SkiaAllCode is the text to add to a search to restrict it to the Skia
	// codebase.
	SkiaAllCode = "file:^src/third_party/skia/ package:^chromium$"

	// SkiaInfraBaseQuery is the text to add to a search to restrict it to the
	// Skia Infra codebase.
	SkiaInfraBaseQuery = "file:^skia/buildbot/ package:^chromium$"

	// SkiaAllMarkdown is the text to add to a search to restrict it to Markdown
	// files in either the buildbot or skia proper repo.
	SkiaAllMarkdown = "lang:^markdown$ AND (file:^skia/buildbot/ OR file:^src/third_party/skia/) AND package:^chromium$ "
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeSearch

type CodeSearch struct {
	// contains filtered or unexported fields
}

CodeSearch searches code.

func New

func New(client *http.Client) *CodeSearch

New creates a new CodeSearch instance.

func (*CodeSearch) Origin

func (cs *CodeSearch) Origin(origin string)

Origin allows over-riding the default origin.

func (CodeSearch) Query

func (cs CodeSearch) Query(ctx context.Context, q string, params url.Values) (SearchResponse, error)

Query runs a search against the given search service.

The query string should conform to any query you would use on https://cs.chromium.org/.

func (CodeSearch) URL

func (cs CodeSearch) URL(r SearchResult) string

URL returns the link to display the TopFile in the SearchResult.

type CompoundSearchResponse

type CompoundSearchResponse struct {
	Response []SearchResponse `json:"search_response"`
}

CompoundSearchResponse represents multiple search responses.

type File

type File struct {
	Name        string `json:"name"`
	PackageName string `json:"package_name"`
}

File is a file in a search result.

type SearchResponse

type SearchResponse struct {
	Status                        int            `json:"status"`
	StatusMessage                 string         `json:"status_message"`
	EstimatedTotalNumberOfResults int            `json:"estimated_total_number_of_results"`
	ResultsOffset                 int            `json:"results_offset"`
	NextPageToken                 string         `json:"next_page_token"`
	SearchResult                  []SearchResult `json:"search_result"`
}

SearchResponse is the response from CodeSearch.Query.

type SearchResult

type SearchResult struct {
	TopFile                TopFile   `json:"top_file"`
	NumDuplicates          int       `json:"num_duplicates"`
	NumMatches             int       `json:"num_matches"`
	Language               string    `json:"language"`
	BestMatchingLineNumber int       `json:"best_matching_line_number"`
	Snippet                []Snippet `json:"snippet"`
}

SearchResult is a single result from a search.

type Snippet

type Snippet struct {
	Text            Text `json:"text"`
	FirstLineNumber int  `json:"first_line_number"`
}

Snippet is a matching snippet of code in a search result.

type Text

type Text struct {
	Text string `json:"text"`
}

Text is the text of a snippet.

type TopFile

type TopFile struct {
	File File `json:"file"`
	Size int  `json:"size"`
}

TopFile is the best matching file in a search result.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL