Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1broseidon Ketch search Provider

From Leeroopedia
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

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment