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
- func FetchMissing(ctx context.Context, e Engine, sy *Syncer, mode string, ...) bool
- func SeedSampleDoc(ctx context.Context, db *localdb.DB, manifest domain.SampleManifest, ...) error
- func WarmKeys(projectPkgs []domain.PURL, recent, hot, pinned []string) []string
- type CorpusCache
- type Engine
- type Syncer
Constants ¶
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.
Types ¶
type CorpusCache ¶ added in v0.1.41
type CorpusCache struct {
// contains filtered or unexported fields
}
CorpusCache holds the parsed local corpus between queries.
The engine re-read and re-parsed all of it on every single query: 1,770 sample manifests and 974 shard rows holding 12 MB of JSON on the install this was measured on, with no warm-up curve at all — three identical queries back to back cost the same each time.
Nothing in that work depends on the question. What does depend on the question is the FTS score, and that is why it no longer lives on the candidate: a value normalised against one query's best hit must not be read by the next, and two searches at once must not write the same field.
A nil cache is a working engine that simply reloads each time, which is what the CLI wants for a single command.
func NewCorpusCache ¶ added in v0.1.41
func NewCorpusCache() *CorpusCache
NewCorpusCache returns a cache ready to be shared by every search a long-lived process runs.
func (*CorpusCache) Loads ¶ added in v0.1.41
func (c *CorpusCache) Loads() int64
Loads reports how many times the corpus has been read from the database.
type Engine ¶
type Engine struct {
DB *localdb.DB
// Corpus keeps the parsed corpus between queries in a long-lived
// process. Nil is a working engine that reloads each time, which is what
// a one-shot CLI command wants.
Corpus *CorpusCache
}
Engine runs searches over one local store.
func (Engine) Search ¶
func (e Engine) Search(ctx context.Context, req domain.SearchRequest) domain.SearchResponse
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
// Progress, when set, is called after each key with how many keys have
// been walked so far and how many there are. A sync of 1,558 keys took
// fifteen minutes on a 246MB local database and told nobody where it
// was; this is how the daemon publishes it and the CLI renders it.
// nil is the previous behaviour.
Progress func(walked, total int)
}
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 ¶
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.