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 Searcher

From Leeroopedia
Knowledge Sources
Domains Search, Interface_Design
Last Updated 2026-10-27 00:00 GMT

Overview

The search backend contract: a single method that turns a query and limit into ranked results, implemented by every web-search provider.

Description

The Searcher interface in the `search` package is the contract every web-search backend satisfies. It is deliberately minimal — one method, `Search(ctx, query, limit)` — so that the auto fallback chain, the `--multi` federated fuser, and the `--random` shuffled fallback can all treat providers uniformly. The companion Result struct carries the URL, title, description, optional content, and (under federated search) the list of backends that returned it.

This is one of three independent Searcher interfaces in ketch (`search.Searcher`, `code.Searcher`, `docs.Searcher`); they never share backends or result types.

Usage

Import this interface when implementing a new search backend, or when writing code that must accept any search provider generically (the auto/multi/random wrappers do this). Callers that need to know which provider answered use the `SelectingSearcher` extension instead.

Code Reference

Source Location

  • Repository: ketch
  • File: search/search.go

Signature

// Result represents a single search result.
type Result struct {
	Title       string   `json:"title"`
	URL         string   `json:"url"`
	FetchedURL  string   `json:"fetched_url,omitempty"`
	Description string   `json:"description,omitempty"`
	Content     string   `json:"content,omitempty"`
	// Backends lists the backends that returned this result under federated
	// (--multi) search. Empty (and omitted) for single-backend results.
	Backends []string `json:"backends,omitempty"`
}

// Searcher is the interface for search backends.
type Searcher interface {
	Search(ctx context.Context, query string, limit int) ([]Result, error)
}

Import

import "github.com/1broseidon/ketch/search"

I/O Contract

Inputs

Name Type Required Description
ctx context.Context Yes Bounds the search; cancellation propagates to the backend
query string Yes The search query string
limit int Yes Max results to return

Outputs

Name Type Description
return []Result Ranked search results; a zero-length slice is a valid success
return error error Non-nil on backend/network failure; a nil error with empty results is a legitimate "no matches"

Usage Examples

Implementing a Backend

package search

import "context"

type myBackend struct{}

func (b *myBackend) Search(ctx context.Context, query string, limit int) ([]Result, error) {
	// A zero-result response is a success — do not return an error for it.
	return []Result{
		{Title: "Example", URL: "https://example.com", Description: "An example result"},
	}, nil
}

Calling Generically

// Any Searcher — a single provider, the Auto chain, or a Multi fuser —
// is invoked the same way. The caller never knows which backend answered.
results, err := searcher.Search(ctx, "rust async runtime", 5)

Related Pages

Implements Principle

Implements Principle

Page Connections

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