search

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package search assembles the one pipeline every search surface shares: fetch full-text and recorded-reason candidates in parallel, filter them by path, rerank the full-text pool structurally, absorb the intent hits as evidence, and cut the answer down to the hits that can justify themselves. MCP and the CLI both call this service, so the two cannot drift into answering the same query differently.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Params

type Params struct {
	Query string
	// Limit bounds how many files the answer shows, not how many candidates
	// are fetched: the service over-fetches so reranking can promote matches
	// the backend ranked below it. Across several namespaces it is what each
	// one may show, not what they share — see SearchFederated.
	Limit       int
	Offset      int
	PathPrefix  string
	IncludeWeak bool
}

Params is one search request as every surface phrases it. @intent give MCP and the CLI the same request shape so their answers stay comparable.

type Searcher

type Searcher interface {
	Query(ctx context.Context, query string, limit int) ([]graph.Node, error)
	QueryIntent(ctx context.Context, query string, limit int) (intentapp.Result, error)
}

Searcher answers one query from both indexes a search runs over: the full-text index of names and content, and the recorded-reason index of @intent/@domainRule text. One port because the two answers are two halves of the same question — a caller wired for only one would answer it worse without any way to see that from the types. @intent keep the service on fetch-only ports so no backend or scoring package leaks in.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service runs the shared search pipeline over one candidate searcher. @intent hold the fetch→filter→rerank→evidence chain in one place instead of one copy per inbound adapter.

func New

func New(searcher Searcher) *Service

New constructs the shared search service. @intent keep construction trivial so composition roots stay declarative.

func (*Service) Search

func (s *Service) Search(ctx context.Context, p Params) (evidence.List, error)

Search answers one query within the namespace already on the context.

The whole pool is reranked rather than just Limit of it: the evidence cut decides membership, so bounding the rerank would spend slots on candidates that are about to be dropped anyway. @intent answer a search with the files that can justify their place, not the backend's raw order. @ensures returns at most Limit files, each carrying every hit it answered with.

func (*Service) SearchFederated

func (s *Service) SearchFederated(ctx context.Context, namespaces []string, p Params) (evidence.List, error)

SearchFederated answers one query across an explicit namespace set.

Each namespace stays its own ranked list so fusion charges a hit the rank it held in its own namespace, not its offset in a concatenated slice.

Limit is what each repository may show, not what they share. Sharing it meant the repositories competed: a limit smaller than the namespace count silenced the ones at the back outright, and the quota that was supposed to prevent that took its slots out of the middle of the ranked list, which left no offset that could resume the page. A budget each repository holds on its own removes the competition, so none of the three has anywhere to come from.

@intent answer one search across several repositories with per-item namespace labels. @domainRule each namespace is queried in isolation and spends its own file budget, so no namespace with hits can be crowded off the page by another.

Directories

Path Synopsis
@index Pure search-document content construction from graph nodes and annotations.
@index Pure search-document content construction from graph nodes and annotations.
@index Turns ranked search candidates into a list a reader can judge.
@index Turns ranked search candidates into a list a reader can judge.
Package identtoken is the one place search text turns into tokens: Fields cuts free text into identifier-like terms, and Split cuts one identifier into its sub-tokens.
Package identtoken is the one place search text turns into tokens: Fields cuts free text into identifier-like terms, and Split cuts one identifier into its sub-tokens.
@index Recorded-reason retrieval: the intent index port and its answer types.
@index Recorded-reason retrieval: the intent index port and its answer types.
@index BM25 scoring of recorded reasons against a plain-language question, shared by every search backend.
@index BM25 scoring of recorded reasons against a plain-language question, shared by every search backend.
Package offsetrule holds one rule about a page position and the one sentence every surface turns a bad position away with.
Package offsetrule holds one rule about a page position and the one sentence every surface turns a bad position away with.
Package queryterm holds the query-side vocabulary rules that both ways of searching this graph have to agree on: the full-text query built for the database, and the term list the fallback scan matches nodes against.
Package queryterm holds the query-side vocabulary rules that both ways of searching this graph have to agree on: the full-text query built for the database, and the term list the fallback scan matches nodes against.
Package rank reranks FTS-ranked code-search candidates using dependency-free structural signals (name subsequence similarity, path proximity), so both the CLI `search` command and the MCP `search` tool share one ranking.
Package rank reranks FTS-ranked code-search candidates using dependency-free structural signals (name subsequence similarity, path proximity), so both the CLI `search` command and the MCP `search` tool share one ranking.
Package wire is the serialized form of a search answer — the JSON contract MCP's search tool and the CLI's --json output both speak.
Package wire is the serialized form of a search answer — the JSON contract MCP's search tool and the CLI's --json output both speak.

Jump to

Keyboard shortcuts

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