Implementation:1broseidon Ketch search Provider
| Knowledge Sources | |
|---|---|
| Domains | Search, Configuration |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
The descriptor that wires one search backend — id, usability predicate, constructor, health probe, settings, and auto-chain rank — and drives config discovery, CLI help, doctor, and auto/multi eligibility.
Description
The Provider struct is the unit of the ordered search registry. Each of the 13 backends is registered by appending one `*Provider()` call to the package-level `providers` slice (explicit, no `init()`). The descriptor carries everything shared consumers need: `ID`/`Name` for display, `Usable` for the no-network precondition check, `New` for construction, `Probe` for the doctor health check, `Settings` for config discovery, and `AutoRank`/`AutoEligible` for placement in the `auto` fallback chain. `Build` is the single safe construction path: it calls `Usable` first and returns the `Setup` message when the provider is not usable.
Usage
Use this when adding a new search backend (see Implementation:1broseidon_Ketch_configbase_Setting for declaring settings) or when introspecting the registry from shared consumers. Never call `New` directly outside `Build`.
Code Reference
Source Location
- Repository: ketch
- File: search/registry.go
Signature
type Provider struct {
MinProbeTimeout time.Duration
ID string
Setup string
Name string
Hidden bool
// AutoRank places the provider in the "auto" chain: zero keeps it out,
// lower non-zero ranks are tried first. Rank is the tiebreak — configured
// providers promote ahead of keyless defaults.
AutoRank int
// AutoEligible gates chain membership on config beyond Usable (SearXNG).
AutoEligible func(*config.Config) bool
Usable func(*config.Config) bool
Settings []config.Setting
New func(*config.Config) (Searcher, error)
Probe func(context.Context, *http.Client, *config.Config) (health.Status, string)
}
// Build applies Usable before construction.
func (p Provider) Build(cfg *config.Config) (Searcher, error)
// Configured reports explicitly set credentials (promotes in auto, gates doctor).
func (p Provider) Configured(cfg *config.Config) bool
// InAuto reports whether the provider may serve the "auto" backend for cfg.
func (p Provider) InAuto(cfg *config.Config) bool
// Required reports whether a failing health check must fail doctor.
func (p Provider) Required(cfg *config.Config) bool
Import
import (
"github.com/1broseidon/ketch/search"
"github.com/1broseidon/ketch/health"
config "github.com/1broseidon/ketch/internal/configbase"
)
I/O Contract
Inputs (Build)
| Name | Type | Required | Description |
|---|---|---|---|
| cfg | *config.Config | Yes | Config to test usability against |
Outputs (Build)
| Name | Type | Description |
|---|---|---|
| return | search.Searcher | The constructed backend |
| return error | error | The descriptor's Setup message when Usable returns false; otherwise New's error |
Usage Examples
Registering a Provider
var providers = []Provider{
braveProvider(),
ddgProvider(),
// append your provider here — order is the stable presentation order
}
func myProvider() Provider {
return Provider{
ID: "mybackend",
Name: "My Backend",
Setup: "set mybackend_api_key to use the My Backend search API",
AutoRank: 30, // lower non-zero = tried earlier in the auto chain
Usable: func(c *config.Config) bool { return c.String("mybackend_api_key") != "" },
Settings: []config.Setting{config.KeyPool("mybackend_api_key", "mybackend_api_keys")},
New: newMyBackend,
Probe: probeMyBackend,
}
}
Building a Resolved Provider
p, ok := search.Lookup("brave")
if !ok {
return fmt.Errorf("%w %q", search.ErrUnknownBackend, "brave")
}
searcher, err := p.Build(cfg) // Usable checked first; Setup message on failure