search

package
v0.1.30 Latest Latest
Warning

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

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

Documentation

Overview

Package search implements the local search engine over the SQLite store: candidate collection from cached samples, compatibility shards, and the FTS index; C7 score fusion; environment grading with the always-sensitive execution-context axis (docs/execution-context.md §5); and §11.5 delta construction. NO_SAFE_MATCH (Miss) is deliberately better than a wrong HIT (goal.md §3.8).

Package search implements the local search side of CodeSampleX: shard syncing/warming plus (in sibling files) ranking and grading over the local SQLite store. Shards are read-only compatibility summaries pulled from the server; nothing in this package uploads anything.

Index

Constants

View Source
const DefaultLimit = 3

DefaultLimit is the result count when the request omits Limit (C7).

Variables

This section is empty.

Functions

func FetchMissing added in v0.1.4

func FetchMissing(ctx context.Context, e Engine, sy *Syncer, mode string, req domain.SearchRequest) bool

FetchMissing pulls the shards for packages the caller NAMED but this machine has never synced, and reports whether anything new arrived.

It exists because of the shape of the actual question. `csx sync` warms the shards for packages already in the local inventory plus the server's HOT list — and the library an agent asks about is, in the normal case, one it is ABOUT TO ADD. That package is in neither list, so the network could hold a verified answer and this machine would return NO_SAFE_MATCH, advising a `csx sync` that would never fetch it.

Only on a miss, only for packages the caller named, and never from the dependency tree: the tree is context, and fetching a shard names the package to the server.

Community mode only. In local-only mode the whole point is that nothing about the caller's work leaves, and asking for a shard by name would announce the exact interest that mode exists to keep private — so a local-only install answers from what it has, and says so.

func SeedSampleDoc

func SeedSampleDoc(ctx context.Context, db *localdb.DB, manifest domain.SampleManifest, sampleID, status string) error

SeedSampleDoc saves a sample's case + metadata row and indexes its FTS document (kind "sample") in one step. It is the shared ingestion helper for tests, shard warm-up, and sample install: anything that makes a sample locally searchable goes through here so the samples table and the FTS index never drift apart.

func WarmKeys

func WarmKeys(projectPkgs []domain.PURL, recent, hot, pinned []string) []string

WarmKeys builds the shard warm list in §11.2 priority order: current project deps → recently used → global HOT → pinned, deduplicated with first occurrence winning. Keys are "ecosystem/name/major" (major from PURL.Major, e.g. "1", golang "v1").

Types

type Engine

type Engine struct {
	DB *localdb.DB
}

Engine runs searches over one local store.

func (Engine) Search

Search implements the C7 pipeline: candidate collection (package / symbol / error-fingerprint / FTS sources), score fusion, environment gate + execution-context rules, verification-strength rerank, recency decay, and the known-failure demotion. Best score below the threshold means NO_SAFE_MATCH: Miss=true, no results.

type Syncer

type Syncer struct {
	DB        *localdb.DB
	HTTP      *http.Client
	ServerURL string
}

Syncer performs ETag-aware conditional GETs of compatibility shards (contract C6) and indexes their contents into the local FTS table so offline search keeps working during server outages (goal.md §3.9).

func (*Syncer) SyncAll

func (s *Syncer) SyncAll(ctx context.Context, keys []string) (int, error)

SyncAll syncs every key, continuing past individual failures so one unreachable shard (or a down server) never blocks the rest (goal.md §3.9). All failures are aggregated into the returned error. SyncAll warms every key and returns HOW MANY ACTUALLY SUCCEEDED.

It used to return only an error, and the caller reported len(keys) as the warmed count — so a sync that failed every key still printed "warmed shard keys: 124" and exited 0. A count of what was attempted is not a count of what worked, and the user was reading it as the latter.

func (*Syncer) SyncKey

func (s *Syncer) SyncKey(ctx context.Context, key string) error

Directories

Path Synopsis
Package relevance provides the provenance-aware lexical gate shared by local and server search.
Package relevance provides the provenance-aware lexical gate shared by local and server search.

Jump to

Keyboard shortcuts

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