search

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 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.

View Source
var ErrRepoFilterUnmatched = errors.New("no requested repo was found in this cell")

ErrRepoFilterUnmatched reports that query-serve answered (the route exists) but the explicit repo filter matched nothing the caller can search — the repo isn't indexed yet, or its owner org isn't enabled on the semantic-search feature flag (entire-search fails closed with a JSON 404, existence not disclosed). A typo'd repo can't produce this from the CLI: the slug was already resolved against the control-plane index before any cell was contacted. Distinct from ErrCellUnavailable so fan-out callers don't misreport a repo-level miss as a region without query-serve.

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"`
	// RerankScore is query-serve's cross-encoder (Cohere) relevance judgement,
	// present only on results that went through reranking. Where present it is
	// the signal the final ordering was built from and the only score
	// comparable across repos — Score is per-namespace retrieval strength, so
	// sorting by it undoes reranking. The cross-cell merge orders tier 0 and
	// tier 1 by this field, matching the BFF (ENT-1425/ENT-1431).
	RerankScore *float64 `json:"rerankScore,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) DedupID added in v0.10.1

func (r *Result) DedupID() string

DedupID is the identity used to collapse cross-cell duplicates. It matches ResultID except for the id types that can REPEAT across repos, which it repo-qualifies so two repos' rows sharing an id don't collide in the deduper and drop a valid result:

  • a raw checkpoint id, and the checkpoint id a server-folded legacy session (ENT-1595) falls back to — checkpoint ids are a mixed space (legacy 12-hex ids repeat across repos; newer ULIDs are global), so qualifying by repo is safe for both and necessary for the legacy half;
  • a commit SHA — globally unique as a content address, but the SAME commit legitimately lives in many repos (a fork and its upstream), so a bare SHA would drop one repo's hit for every shared commit.

Repo ULIDs and real session ids are globally unique, so they pass through. Mirrors of the SAME repo still carry the same org/repo and collapse correctly. ResultID stays the raw, machine-lookup id for display.

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. PR raw payloads carry the author login under "userLogin" (searcher.PRResult).

func (*Result) ResultBranch added in v0.7.6

func (r *Result) ResultBranch() string

ResultBranch returns the branch for any result type. PR raw payloads carry the head branch under "headBranch" (searcher.PRResult).

func (*Result) ResultCheckpointCount added in v0.10.0

func (r *Result) ResultCheckpointCount() int

ResultCheckpointCount returns the indexed checkpoint count for raw-payload repo rows (searcher.RepoResult), 0 elsewhere.

func (*Result) ResultCreatedAt added in v0.7.6

func (r *Result) ResultCreatedAt() string

ResultCreatedAt returns the createdAt for any result type.

func (*Result) ResultDescription added in v0.10.0

func (r *Result) ResultDescription() string

ResultDescription returns the repo description for raw-payload rows (searcher.RepoResult). Typed rows return "" — rawFields is never populated for them.

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. Repo/PR raw payloads may only carry an owner-qualified "fullName"; its owner segment is the org.

func (*Result) ResultRepo added in v0.7.6

func (r *Result) ResultRepo() string

ResultRepo returns the bare repo name (no owner) for any result type, so callers can join it with ResultOrg without doubling the owner. Repo/PR raw payloads carry it under "repo" or "name", or qualified inside "fullName".

func (*Result) ResultTitle added in v0.7.6

func (r *Result) ResultTitle() string

ResultTitle returns the primary display text for any result type. Repo/PR raw payloads identify themselves via "title", "name", or "fullName".

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"`
	// MatchedCheckpointID is the carrier checkpoint the search service anchors a
	// session row to — present on every session row. For a server-folded legacy
	// session (ENT-1595) the sessionId is empty and this IS the row's identity
	// (the checkpoint predates the sessionId attribute), so ResultID and the
	// cross-cell dedupe (DedupID) fall back to it, repo-qualified, and a mirrored
	// repo reports the row once instead of twice. Drill-down is
	// `entire checkpoint explain <id>`, not `entire session info`.
	MatchedCheckpointID string  `json:"matchedCheckpointId,omitempty"`
	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