search

package
v0.0.0-...-165bdb7 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package search provides gRPC handlers for the search service.

Package search provides code search functionality using Zoekt.

Package search provides code search functionality using Zoekt.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	IndexDir   string // Directory for Zoekt indexes
	CacheDir   string // Directory for git clones during indexing
	Workers    int    // Number of concurrent indexing workers
	QueueSize  int    // Size of job queue
	RouterAddr string // Router address for cluster access (enables fetching from storage nodes)
	Logger     *slog.Logger
}

Config holds service configuration

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns default configuration

type IndexLocalRequest

type IndexLocalRequest struct {
	StorageID   string
	DisplayPath string
	SourceDir   string
	Ref         string
}

IndexLocalRequest contains parameters for indexing a local directory

type IndexRequest

type IndexRequest struct {
	StorageID   string
	DisplayPath string
	RepoURL     string
	Ref         string
}

IndexRequest contains repository indexing parameters

type IndexResult

type IndexResult struct {
	FilesIndexed   int64
	IndexSizeBytes int64
	Duration       time.Duration
}

IndexResult contains indexing results

type Indexer

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

Indexer manages Zoekt indexing and searching

func NewIndexer

func NewIndexer(indexDir, cacheDir string, monofsClient client.MonoFSClient, logger *slog.Logger) (*Indexer, error)

NewIndexer creates a new Zoekt indexer

func (*Indexer) Close

func (i *Indexer) Close() error

Close closes the indexer

func (*Indexer) DeleteIndex

func (i *Indexer) DeleteIndex(displayPath string) error

DeleteIndex removes the index for a repository by display path

func (*Indexer) GetIndexSize

func (i *Indexer) GetIndexSize(displayPath string) (int64, error)

GetIndexSize returns the index size for a repository by display path

func (*Indexer) IndexExists

func (i *Indexer) IndexExists(displayPath string) bool

IndexExists checks if an index exists for a repository by display path

func (*Indexer) IndexLocalDir

func (i *Indexer) IndexLocalDir(ctx context.Context, req IndexLocalRequest) (*IndexResult, error)

IndexLocalDir indexes a local directory directly (for testing)

func (*Indexer) IndexRepository

func (i *Indexer) IndexRepository(ctx context.Context, req IndexRequest) (*IndexResult, error)

IndexRepository indexes a git repository

func (*Indexer) RegisterStorageMapping

func (i *Indexer) RegisterStorageMapping(displayPath, storageID string)

RegisterStorageMapping registers a DisplayPath to StorageID mapping. This allows the Search function to return StorageID in results. Call this for all known repositories on startup.

func (*Indexer) ReloadSearcher

func (i *Indexer) ReloadSearcher() error

ReloadSearcher reloads the searcher to pick up new indexes

func (*Indexer) Search

func (i *Indexer) Search(ctx context.Context, req SearchRequest) (*SearchResults, error)

Search performs a code search

type Job

type Job struct {
	ID           string         `json:"id"`
	StorageID    string         `json:"storage_id"`
	DisplayPath  string         `json:"display_path"`
	RepoURL      string         `json:"repo_url"`
	Branch       string         `json:"branch"`
	Status       pb.IndexStatus `json:"status"`
	Progress     float32        `json:"progress"`
	FilesCount   int64          `json:"files_count"`
	IndexSize    int64          `json:"index_size"`
	QueuedAt     time.Time      `json:"queued_at"`
	StartedAt    time.Time      `json:"started_at"`
	CompletedAt  time.Time      `json:"completed_at"`
	ErrorMessage string         `json:"error_message"`
}

Job represents an indexing job

type MatchRange

type MatchRange struct {
	Start int
	End   int
}

MatchRange indicates match position

type RepoMeta

type RepoMeta struct {
	StorageID   string    `json:"storage_id"`
	DisplayPath string    `json:"display_path"`
	RepoURL     string    `json:"repo_url"`
	Branch      string    `json:"branch"`
	FilesCount  int64     `json:"files_count"`
	IndexSize   int64     `json:"index_size"`
	LastIndexed time.Time `json:"last_indexed"`
}

RepoMeta stores repository metadata for search

type SearchRequest

type SearchRequest struct {
	Query         string
	StorageID     string // Optional: limit to specific repo
	MaxResults    int
	CaseSensitive bool
	Regex         bool
	FilePatterns  []string
}

SearchRequest contains search parameters

type SearchResult

type SearchResult struct {
	StorageID     string
	DisplayPath   string
	FilePath      string
	LineNumber    int
	LineContent   string
	Matches       []MatchRange
	BeforeContext string
	AfterContext  string
}

SearchResult contains a single search match

type SearchResults

type SearchResults struct {
	Results       []SearchResult
	TotalMatches  int64
	FilesSearched int64
	Duration      time.Duration
	Truncated     bool
}

SearchResults contains all search results

type Service

type Service struct {
	pb.UnimplementedMonoFSSearchServer
	// contains filtered or unexported fields
}

Service implements the MonoFSSearch gRPC service

func NewService

func NewService(cfg Config) (*Service, error)

NewService creates a new search service

func (*Service) Close

func (s *Service) Close() error

Close shuts down the service

func (*Service) DeleteIndex

func (s *Service) DeleteIndex(ctx context.Context, req *pb.DeleteIndexRequest) (*pb.DeleteIndexResponse, error)

DeleteIndex implements the DeleteIndex RPC

func (*Service) GetIndexStatus

func (s *Service) GetIndexStatus(ctx context.Context, req *pb.IndexStatusRequest) (*pb.IndexStatusResponse, error)

GetIndexStatus implements the GetIndexStatus RPC

func (*Service) GetStats

func (s *Service) GetStats(ctx context.Context, req *pb.StatsRequest) (*pb.StatsResponse, error)

GetStats implements the GetStats RPC

func (*Service) IndexRepository

func (s *Service) IndexRepository(ctx context.Context, req *pb.IndexRequest) (*pb.IndexResponse, error)

IndexRepository implements the IndexRepository RPC

func (*Service) ListIndexes

func (s *Service) ListIndexes(ctx context.Context, req *pb.ListIndexesRequest) (*pb.ListIndexesResponse, error)

ListIndexes implements the ListIndexes RPC

func (*Service) RebuildAllIndexes

RebuildAllIndexes implements the RebuildAllIndexes RPC

func (*Service) RebuildIndex

func (s *Service) RebuildIndex(ctx context.Context, req *pb.RebuildIndexRequest) (*pb.RebuildIndexResponse, error)

RebuildIndex implements the RebuildIndex RPC

func (*Service) Search

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

Search implements the Search RPC

type ServiceStats

type ServiceStats struct {
	SearchesTotal       int64     `json:"searches_total"`
	SearchDurationTotal int64     `json:"search_duration_total_ms"`
	StartedAt           time.Time `json:"started_at"`
	JobsQueued          int64     `json:"jobs_queued"`
	JobsCompleted       int64     `json:"jobs_completed"`
	JobsFailed          int64     `json:"jobs_failed"`
	JobsRejected        int64     `json:"jobs_rejected"`
}

ServiceStats tracks service statistics

Jump to

Keyboard shortcuts

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