search

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package search provides search functionality via the Entire search service.

Index

Constants

View Source
const (
	TypeCheckpoint = "checkpoint"
	TypeCommit     = "commit"
	TypeSession    = "session"
	// TypeRepo and TypePR are returned by the backend but have no typed struct
	// (decoded via rawData). They're named so the cross-cell v4 merge can bucket
	// and tally them without string literals.
	TypeRepo = "repo"
	TypePR   = "pr"
)

Result type constants.

View Source
const AllReposFilter = "*"

AllReposFilter is the inline repo filter value that disables repo scoping.

View Source
const DefaultLimit = 100

DefaultLimit is the default number of results to fetch per request, matching the UI.

View Source
const WildcardQuery = "*"

WildcardQuery is the query string used when only filters are provided (no search terms).

Variables

View Source
var ErrCellUnavailable = errors.New("semantic search is not available in this cell")

ErrCellUnavailable reports that a cell's gateway does not expose the semantic-search route at all (HTTP 404 at the route level) — query-serve is not deployed in that cell yet. Callers fanning out across cells match it with errors.Is and skip the cell quietly instead of warning the user about a "failed" region.

Functions

func AppendUnique added in v0.9.0

func AppendUnique(existing []string, values ...string) []string

AppendUnique appends values to existing, skipping any already present, and returns the result. Order is preserved (first occurrence wins).

func ParseGitHubRemote

func ParseGitHubRemote(remoteURL string) (owner, repo string, err error)

ParseGitHubRemote extracts owner and repo from a git remote URL that resolves to GitHub. It accepts direct GitHub remotes (SCP-style SSH, ssh://, and https://) as well as Entire mirror remotes (entire://host/gh/owner/repo), whose forge prefix maps back to github.com. Remotes resolving to any other host, or whose path holds extra segments beyond owner/repo, are rejected.

func ValidateRepoFilters

func ValidateRepoFilters(repos []string) error

ValidateRepoFilters ensures each repo filter matches backend semantics. Multiple explicit repo filters are accepted: the v4 query-serve path resolves each and fans out across the cells hosting them, mirroring code search.

Types

type CheckpointResult

type CheckpointResult struct {
	ID             string   `json:"id"`
	Prompt         string   `json:"prompt"`
	CommitMessage  *string  `json:"commitMessage"`
	CommitSubject  *string  `json:"commitSubject"`
	CommitSHA      *string  `json:"commitSha"`
	Branch         string   `json:"branch"`
	Org            string   `json:"org"`
	Repo           string   `json:"repo"`
	Author         string   `json:"author"`
	AuthorUsername *string  `json:"authorUsername"`
	CreatedAt      string   `json:"createdAt"`
	FilesTouched   []string `json:"filesTouched"`
}

CheckpointResult represents a checkpoint returned by the search service.

type CommitResult added in v0.7.6

type CommitResult struct {
	ID             string  `json:"id"`
	CommitSHA      string  `json:"commitSha"`
	CommitMessage  string  `json:"commitMessage"`
	CommitSubject  string  `json:"commitSubject"`
	Branch         string  `json:"branch"`
	Org            string  `json:"org"`
	Repo           string  `json:"repo"`
	Author         string  `json:"author"`
	AuthorUsername *string `json:"authorUsername"`
	CreatedAt      string  `json:"createdAt"`
	Additions      int     `json:"additions"`
	Deletions      int     `json:"deletions"`
	FilesChanged   int     `json:"filesChanged"`
	HTMLUrl        *string `json:"htmlUrl"`
}

CommitResult represents a commit returned by the search service.

type Config

type Config struct {
	Owner    string
	Repo     string
	Repos    []string
	AllRepos bool // When true, search all accessible repos (no repo scoping)
	Query    string
	Limit    int
	Author   string // Filter by author name
	Date     string // Filter by time period: "week" or "month"
	Branch   string // Filter by branch name
	Page     int    // 1-based page number (0 means omit, API defaults to 1)
}

Config holds the configuration for a search request.

func (Config) HasFilters

func (c Config) HasFilters() bool

HasFilters reports whether any filter fields are set on the config.

func (Config) ScopeSlugs added in v0.9.0

func (c Config) ScopeSlugs() (slugs []string, allRepos bool)

ScopeSlugs resolves the repo scope of a search: the explicit repo filters (an explicit owner/name filter always scopes the search, even when --all-repos is also set — the more specific filter wins), else allRepos for an unfiltered repo:* / --all-repos search, else the current-repo default. slugs empty with allRepos false means no scope could be determined.

type Meta

type Meta struct {
	MatchType string   `json:"matchType"`
	Score     float64  `json:"score"`
	Tier      *int     `json:"tier,omitempty"`
	Snippet   string   `json:"snippet,omitempty"`
	Summary   string   `json:"summary,omitempty"`
	BM25Score *float64 `json:"bm25Score,omitempty"`
	ANNScore  *float64 `json:"annScore,omitempty"`
}

Meta contains search ranking metadata for a result.

type ParsedInput

type ParsedInput struct {
	Query  string
	Author string
	Date   string
	Branch string
	Repos  []string
}

ParsedInput holds the parsed query and optional filters extracted from search input.

func ParseSearchInput

func ParseSearchInput(raw string) ParsedInput

ParseSearchInput extracts filter prefixes from raw input. Supports quoted values for single-value filters, for example: author:"alice smith". Remaining tokens become the query.

type Response

type Response struct {
	Results  []Result    `json:"results"`
	Total    int         `json:"total"`
	Page     int         `json:"page"`
	Error    string      `json:"error,omitempty"`
	Timing   *Timing     `json:"timing,omitempty"`
	Reranked *bool       `json:"reranked,omitempty"`
	Counts   *TypeCounts `json:"counts,omitempty"`

	// Warnings are client-side completeness notes (e.g. a truncated repo
	// index or a failed region in a cross-cell fan-out) surfaced to the user
	// on stderr. Never part of the wire format.
	Warnings []string `json:"-"`
}

Response is the search service response.

func CellV4 added in v0.9.0

func CellV4(ctx context.Context, client *api.Client, cfg Config, repoIDs []string) (*Response, error)

CellV4 performs a v4 query-serve search against a single entire-api cell, via the pre-authenticated client (bearer = jurisdictional identity token; host = the cell). repoIDs are repo ULIDs to scope to (the v4 route is per-repo and keys on ULIDs, not owner/name slugs); an empty repoIDs means "every repo the caller can access in this cell" — query-serve fans out across those namespaces itself. The cross-cell fan-out and merge live in the cli layer (mirroring code search), so this is the single-cell primitive it calls.

type Result

type Result struct {
	Type       string            `json:"-"`
	Meta       Meta              `json:"-"`
	Checkpoint *CheckpointResult `json:"-"`
	Commit     *CommitResult     `json:"-"`
	Session    *SessionResult    `json:"-"`
	// contains filtered or unexported fields
}

Result wraps a search result with its type and ranking metadata. Exactly one of Checkpoint, Commit, or Session is non-nil based on Type.

func (*Result) MarshalJSON added in v0.7.6

func (r *Result) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling to produce the API wire format.

func (*Result) ResultAuthor added in v0.7.6

func (r *Result) ResultAuthor() string

ResultAuthor returns the display author for any result type.

func (*Result) ResultBranch added in v0.7.6

func (r *Result) ResultBranch() string

ResultBranch returns the branch for any result type.

func (*Result) ResultCreatedAt added in v0.7.6

func (r *Result) ResultCreatedAt() string

ResultCreatedAt returns the createdAt for any result type.

func (*Result) ResultID added in v0.7.6

func (r *Result) ResultID() string

ResultID returns the primary ID for any result type. Types without a typed struct (repo, pr) fall back to the "id" field of the raw payload, so a cross-cell merge can still identify the same logical result returned by two cells (e.g. a repo mirrored in both).

func (*Result) ResultOrg added in v0.7.6

func (r *Result) ResultOrg() string

ResultOrg returns the org for any result type.

func (*Result) ResultRepo added in v0.7.6

func (r *Result) ResultRepo() string

ResultRepo returns the repo for any result type.

func (*Result) ResultTitle added in v0.7.6

func (r *Result) ResultTitle() string

ResultTitle returns the primary display text for any result type.

func (*Result) UnmarshalJSON added in v0.7.6

func (r *Result) UnmarshalJSON(b []byte) error

UnmarshalJSON implements custom JSON unmarshaling to parse typed data.

type SessionResult added in v0.7.6

type SessionResult struct {
	SessionID      string  `json:"sessionId"`
	DisplayName    string  `json:"displayName"`
	Prompt         *string `json:"prompt"`
	Agent          *string `json:"agent"`
	Model          *string `json:"model"`
	StepCount      int     `json:"stepCount"`
	Org            string  `json:"org"`
	Repo           string  `json:"repo"`
	Branch         *string `json:"branch"`
	AuthorUsername *string `json:"authorUsername"`
	CreatedAt      string  `json:"createdAt"`
}

SessionResult represents a session returned by the search service.

type Timing added in v0.7.6

type Timing struct {
	TotalMs            *float64 `json:"total_ms"`
	KeywordMs          *float64 `json:"keyword_ms"`
	EmbeddingMs        *float64 `json:"embedding_ms"`
	VectorMs           *float64 `json:"vector_ms"`
	RerankMs           *float64 `json:"rerank_ms"`
	FanoutMs           *float64 `json:"fanout_ms"`
	SessionHydrationMs *float64 `json:"session_hydration_ms"`
}

Timing holds search performance timing data.

type TypeCounts added in v0.7.6

type TypeCounts struct {
	Repos       int `json:"repos"`
	Checkpoints int `json:"checkpoints"`
	Commits     int `json:"commits"`
	PRs         int `json:"prs"`
	Sessions    int `json:"sessions"`
}

TypeCounts holds per-type result counts.

Jump to

Keyboard shortcuts

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