search

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package search provides chunk types, file-to-chunk splitting, and in-memory full-text search with BM25 scoring.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveStrategy

func ResolveStrategy(strategy, filename string) string

ResolveStrategy picks a strategy when the user provides "" (auto).

Types

type Chunk

type Chunk struct {
	// Source is the file path relative to the project root.
	Source string
	// Section is the heading hierarchy (e.g. "## Ownership > ### Cross-namespace").
	Section string
	// Title is the heading text or key name.
	Title string
	// Body is the full text content of the section.
	Body string
	// Tags are metadata labels (from config or auto-derived).
	Tags []string
	// ConventionID links this chunk to a convention (empty if from file source).
	ConventionID string
	// Docs lists documentation paths associated with a convention chunk.
	Docs []string
}

Chunk is the atomic unit of searchable content.

func ChunkContent

func ChunkContent(source, content, strategy string) []Chunk

ChunkContent splits content into chunks using the given strategy. strategy must be "section", "file", or "none".

type Index

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

Index is an in-memory search index over chunks. It is safe for concurrent use: Search acquires a read lock, Merge acquires a write lock.

func NewIndex

func NewIndex(chunks []Chunk) *Index

NewIndex creates an index from chunks.

func (*Index) Len

func (idx *Index) Len() int

Len returns the number of indexed chunks.

func (*Index) Merge

func (idx *Index) Merge(chunks []Chunk) int

Merge appends new chunks to the index. It is safe for concurrent use with Search; callers can merge in additional content while searches continue. Returns the number of chunks added.

func (*Index) Search

func (idx *Index) Search(query string, maxResults int) []Result

Search returns the top-N chunks matching the query, ranked by score. Scoring: body match (BM25) + title boost (3x) + tag exact match (5x). It is safe for concurrent use with Merge.

type LiveIndex

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

LiveIndex provides safe atomic access to a swappable Index. Create with NewLiveIndex. Safe for concurrent use; Get and Len can be called freely alongside Swap.

func NewLiveIndex

func NewLiveIndex() *LiveIndex

NewLiveIndex returns a LiveIndex backed by an empty index.

func (*LiveIndex) Get

func (h *LiveIndex) Get() *Index

Get returns the current index. Safe for concurrent use.

func (*LiveIndex) Len

func (h *LiveIndex) Len() int

Len returns the number of indexed chunks, or 0 if the index is empty. Safe for concurrent use.

func (*LiveIndex) Search

func (h *LiveIndex) Search(query string, maxResults int) []Result

Search runs a query against the current index. Safe for concurrent use.

func (*LiveIndex) Swap

func (h *LiveIndex) Swap(idx *Index)

Swap atomically replaces the current index with idx.

type Result

type Result struct {
	Chunk Chunk
	Score float64
}

Result is a scored search result.

type Searcher

type Searcher interface {
	Search(query string, maxResults int) []Result
	Len() int
}

Searcher is implemented by both *Index (static) and *LiveIndex (live/swappable). Use this type when callers do not need to distinguish between the two.

Jump to

Keyboard shortcuts

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