search

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client communicates with the Zoekt webserver via gRPC.

func NewClient

func NewClient(zoektURL string) *Client

NewClient creates a new Zoekt gRPC client.

func (*Client) Close

func (c *Client) Close() error

Close closes the gRPC connection.

func (*Client) Health

func (c *Client) Health(ctx context.Context) error

Health checks if the Zoekt service is healthy.

func (*Client) ListRepos

func (c *Client) ListRepos(ctx context.Context) ([]RepoInfo, error)

ListRepos returns a list of indexed repositories.

func (*Client) Search

func (c *Client) Search(ctx context.Context, q Query) (*SearchResponse, error)

Search performs a search query against Zoekt via gRPC.

func (*Client) StreamSearch

func (c *Client) StreamSearch(ctx context.Context, q Query) <-chan StreamSearchResult

StreamSearch performs a streaming search using Zoekt's native gRPC streaming. Results are sent on the returned channel as they arrive from Zoekt. The channel is closed when the search is complete or an error occurs.

type File

type File struct {
	Name     string  `json:"name"`
	Language string  `json:"language"`
	Matches  []Match `json:"matches"`
}

File represents a file with matches.

type Match

type Match struct {
	LineNum  int    `json:"line_num"`
	Line     string `json:"line"`
	Before   string `json:"before,omitempty"`
	After    string `json:"after,omitempty"`
	Start    int    `json:"start"`
	End      int    `json:"end"`
	Fragment string `json:"fragment"`
}

Match represents a single match within a file.

type Query

type Query struct {
	Pattern       string
	IsRegex       bool
	CaseSensitive bool
	Repos         []string
	Languages     []string
	FilePatterns  []string
	MaxResults    int
}

Query represents a search query.

type RepoInfo

type RepoInfo struct {
	Name     string   `json:"name"`
	Branches []string `json:"branches"`
	Files    int      `json:"files"`
	Shard    int      `json:"shard,omitempty"` // Which shard this repo is on (for sharded setups)
}

RepoInfo represents information about an indexed repository.

type Result

type Result struct {
	Repo     string   `json:"repo"`
	Branches []string `json:"branches"`
	Files    []File   `json:"files"`
}

Result represents a search result.

type ResultContext

type ResultContext struct {
	Before []string `json:"before"`
	After  []string `json:"after"`
}

ResultContext represents lines around a match.

type SearchRequest

type SearchRequest struct {
	Query         string   `json:"query"`
	IsRegex       bool     `json:"is_regex"`
	CaseSensitive bool     `json:"case_sensitive"`
	Repos         []string `json:"repos,omitempty"`
	Languages     []string `json:"languages,omitempty"`
	FilePatterns  []string `json:"file_patterns,omitempty"`
	Limit         int      `json:"limit"`
	ContextLines  int      `json:"context_lines"`
}

SearchRequest represents a search request.

type SearchResponse

type SearchResponse struct {
	Results      []Result      `json:"results"`
	Stats        Stats         `json:"stats"`
	Duration     time.Duration `json:"duration"`
	TotalMatches int           `json:"total_matches"`
}

SearchResponse represents the response from Zoekt.

type SearchResult

type SearchResult struct {
	Repo       string        `json:"repo"`
	File       string        `json:"file"`
	Line       int           `json:"line"`
	Column     int           `json:"column"`
	Content    string        `json:"content"`
	Context    ResultContext `json:"context"`
	Language   string        `json:"language"`
	MatchStart int           `json:"match_start"`
	MatchEnd   int           `json:"match_end"`
}

SearchResult represents a single search result for API responses.

type SearchResults

type SearchResults struct {
	Results    []SearchResult `json:"results"`
	TotalCount int            `json:"total_count"`
	Truncated  bool           `json:"truncated"`
	Duration   time.Duration  `json:"duration"`
	Stats      SearchStats    `json:"stats"`
}

SearchResults represents the search response.

type SearchStats

type SearchStats struct {
	FilesSearched int `json:"files_searched"`
	ReposSearched int `json:"repos_searched"`
}

SearchStats contains search statistics.

type Service

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

Service provides search functionality.

func NewService

func NewService(zoektURL string) *Service

NewService creates a new search service with a single Zoekt backend.

func NewShardedService

func NewShardedService(zoektURLs string) *Service

NewShardedService creates a search service with multiple Zoekt shards zoektURLs should be comma-separated: "http://zoekt-0:6070,http://zoekt-1:6070"

func (*Service) Close

func (s *Service) Close() error

Close closes all client connections.

func (*Service) Health

func (s *Service) Health(ctx context.Context) error

Health checks if the search service is healthy.

func (*Service) ListIndexedRepos

func (s *Service) ListIndexedRepos(ctx context.Context) ([]RepoInfo, error)

ListIndexedRepos returns a list of indexed repositories from Zoekt.

func (*Service) Search

func (s *Service) Search(ctx context.Context, req SearchRequest) (*SearchResults, error)

Search performs a search and returns formatted results.

func (*Service) StreamSearch

func (s *Service) StreamSearch(ctx context.Context, req SearchRequest) <-chan StreamSearchEvent

StreamSearch performs streaming search and sends results as they arrive. This provides faster time-to-first-result compared to batch Search.

type ShardedClient

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

ShardedClient manages multiple Zoekt clients for horizontal scaling.

func NewShardedClient

func NewShardedClient(shardURLs string) *ShardedClient

NewShardedClient creates a client that can query multiple Zoekt shards shardURLs can be: - Single URL: "http://localhost:6070" (no sharding) - Multiple URLs: "http://zoekt-0:6070,http://zoekt-1:6070,http://zoekt-2:6070" - Kubernetes headless service pattern: "zoekt-{0..2}.zoekt.default.svc:6070".

func (*ShardedClient) Close

func (sc *ShardedClient) Close() error

Close closes all client connections.

func (*ShardedClient) GetClientForRepo

func (sc *ShardedClient) GetClientForRepo(repoName string) *Client

GetClientForRepo returns the client for a specific repository.

func (*ShardedClient) GetShardForRepo

func (sc *ShardedClient) GetShardForRepo(repoName string) int

GetShardForRepo returns the shard index for a repository Uses consistent hashing based on repo name.

func (*ShardedClient) Health

func (sc *ShardedClient) Health(ctx context.Context) error

Health checks all shards and returns overall health.

func (*ShardedClient) ListRepos

func (sc *ShardedClient) ListRepos(ctx context.Context) ([]RepoInfo, error)

ListRepos queries all shards and returns combined repo list.

func (*ShardedClient) Search

func (sc *ShardedClient) Search(ctx context.Context, q Query) (*SearchResponse, error)

Search queries all shards in parallel and merges results.

func (*ShardedClient) ShardCount

func (sc *ShardedClient) ShardCount() int

ShardCount returns the number of shards.

func (*ShardedClient) ShardURLs

func (sc *ShardedClient) ShardURLs() []string

ShardURLs returns the URLs of all shards.

func (*ShardedClient) StreamSearch

func (sc *ShardedClient) StreamSearch(ctx context.Context, q Query) <-chan StreamSearchResult

StreamSearch performs streaming search across all shards in parallel. Results from all shards are merged into a single channel as they arrive. This provides true streaming with faster time-to-first-result.

type Stats

type Stats struct {
	FilesConsidered int           `json:"files_considered"`
	FilesLoaded     int           `json:"files_loaded"`
	FilesSkipped    int           `json:"files_skipped"`
	ShardsScanned   int           `json:"shards_scanned"`
	Duration        time.Duration `json:"duration"`
}

Stats contains search statistics.

type StreamSearchEvent

type StreamSearchEvent struct {
	Result *SearchResult // A single search result
	Stats  *SearchStats  // Stats update
	Done   bool          // Stream complete
	Error  error         // Error if something went wrong
}

StreamSearchResult represents a single result event from streaming search.

type StreamSearchResult

type StreamSearchResult struct {
	Result *Result // A single repository result (may contain multiple files/matches)
	Stats  *Stats  // Partial stats update (sent periodically)
	Done   bool    // Indicates stream is complete
	Error  error   // Error if something went wrong
}

StreamSearchResult represents a single result or event from streaming search.

Jump to

Keyboard shortcuts

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