search

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package search is bumper's unified, cross-corpus rule search. It builds a single in-memory BM25 index over BOTH corpora — the enforced rules (which fire on a plan) and the embedded advisory catalog (Trivy/Checkov/KICS/Prowler knowledge) — then re-ranks with a small custom policy (enforced boost + severity + source priority).

It is deliberately hand-rolled (stdlib only): the corpus is ~2,800 short docs, BM25 is stable write-once math, and a transparent scorer fits bumper's single-static-binary, CGO-free, auditable supply chain better than pulling in a full-text-search engine. Heavy machinery (semantic/vector, hybrid RRF) is reserved for the hosted Advisor, which has no CGO/offline constraint.

Index

Constants

View Source
const DefaultLimit = 30

DefaultLimit caps results when Query.Limit is unset.

Variables

This section is empty.

Functions

This section is empty.

Types

type Doc

type Doc struct {
	Corpus   string         // "enforced" | "advisory"
	Enforced bool           // true for the executable rule set
	Rule     *rules.Rule    // set iff enforced
	Entry    *catalog.Entry // set iff advisory
	// contains filtered or unexported fields
}

Doc is one searchable document spanning both corpora. Exactly one of Rule / Entry is set; callers render from the back-pointer so we don't duplicate fields. The lowercase fields are the indexed text.

func BuildDocs

func BuildDocs(set *rules.Set, cat *catalog.Catalog) []Doc

BuildDocs flattens both corpora into searchable docs.

type Hit

type Hit struct {
	Doc       Doc
	Score     float64
	Relevance float64
}

Hit is a ranked document: Score is the final re-ranked score, Relevance is the raw BM25 contribution (used for the topicality floor).

func Split

func Split(hits []Hit) (enforced, advisory []Hit)

Split partitions ranked hits into the enforced and advisory groups, each preserving rank order.

type Index

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

Index is a BM25 index over a fixed set of docs.

func New

func New(set *rules.Set, cat *catalog.Catalog) *Index

New builds an index directly from the two corpora.

func NewIndex

func NewIndex(docs []Doc) *Index

NewIndex builds a BM25 index over docs.

func (*Index) Search

func (ix *Index) Search(q Query) []Hit

Search runs the query and returns ranked hits across both corpora.

type Query

type Query struct {
	Text     string
	Provider string
	Severity string
	Resource string
	Limit    int // 0 => DefaultLimit
}

Query is a search request. Empty Text with a filter set returns all matching docs ranked by the re-rank policy.

Jump to

Keyboard shortcuts

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