Documentation
¶
Overview ¶
Package search provides format-neutral, revision-bound search over immutable UTF-8 byte sources. Persistent indexes are disposable candidate accelerators: every indexed hit is verified against the bound Source.
Index ¶
- Constants
- Variables
- func Collect(ctx context.Context, directory string) error
- type Analyzer
- type CaseMode
- type IncompleteReason
- type Index
- func Build(ctx context.Context, source Source, revision uint64, options IndexOptions) (*Index, error)
- func BuildOwned(ctx context.Context, source OwnedSource, revision uint64, options IndexOptions) (*Index, error)
- func Open(ctx context.Context, source Source, revision uint64, options IndexOptions) (*Index, error)
- func OpenOrBuild(ctx context.Context, source Source, revision uint64, options IndexOptions) (*Index, error)
- func OpenOrBuildOwned(ctx context.Context, source OwnedSource, revision uint64, options IndexOptions) (*Index, error)
- func OpenOwned(ctx context.Context, source OwnedSource, revision uint64, options IndexOptions) (*Index, error)
- func Rebuild(ctx context.Context, source Source, previous *Index, ...) (*Index, error)
- func RebuildOwned(ctx context.Context, source OwnedSource, previous *Index, ...) (*Index, error)
- type IndexOptions
- type Lineage
- type Match
- type Options
- type OwnedSource
- type Query
- type QueryKind
- type Report
- type Source
- type Stats
- type Token
Constants ¶
const ( DefaultBlockBytes int64 = 64 << 10 MaximumBlockBytes int64 = 64 << 20 DefaultOverlapBytes int64 = 64 MaximumOverlapBytes int64 = 1 << 20 DefaultMaxBlocks = 1 << 20 MaximumBlocks = 16 << 20 DefaultMaxAnalyzerTokensPerBlock = 65_536 MaximumAnalyzerTokensPerBlock = 1_048_576 DefaultMaxAnalyzerTermBytes = 4 << 10 MaximumAnalyzerTermBytes = 1 << 20 MaximumAnalyzerIdentityBytes = 4 << 10 )
const ( DefaultReadBufferBytes int64 = 64 << 10 MaximumReadBufferBytes int64 = 4 << 20 DefaultMaxScannedBytes int64 = 64 << 20 MaximumScannedBytes int64 = 1 << 30 DefaultMaxPatternBytes = 1 << 20 MaximumPatternBytes = 16 << 20 DefaultMaxResults = 1_000 MaximumResults = 1_000_000 DefaultMaxCandidateBlocks = 100_000 MaximumCandidateBlocks = 10_000_000 )
const MaximumAnalyzerQueryTerms = 1_024
Variables ¶
var ( ErrInvalidContext = errors.New("search: nil context") ErrInvalidSource = errors.New("search: invalid source") ErrInvalidQuery = errors.New("search: invalid query") ErrInvalidOptions = errors.New("search: invalid options") ErrInvalidUTF8 = errors.New("search: source is not UTF-8") ErrSourceInconsistent = errors.New("search: source length or content changed") ErrClosed = errors.New("search: index closed") ErrIndexStale = errors.New("search: persistent index is stale") ErrIndexCorrupt = errors.New("search: persistent index is corrupt") ErrAnalyzerMismatch = errors.New("search: analyzer identity mismatch") ErrLineageMismatch = errors.New("search: index lineage mismatch") ErrInvalidIndex = errors.New("search: invalid previous index") )
Functions ¶
Types ¶
type Analyzer ¶
type Analyzer interface {
Identity() string
RequiredOverlapBytes() int64
Analyze(context.Context, []byte) ([]Token, error)
QueryTerms(context.Context, string) ([]string, error)
}
Analyzer injects language or host-specific "word" policy without teaching the core any document format. Analyze must return deterministic tokens for the same UTF-8 block. QueryTerms returns normalized alternatives for one Term query.
RequiredOverlapBytes must cover both token length and any boundary context the Analyzer needs. Build stores only tokens whose Start lies in a block's non-overlapping core.
type CaseMode ¶
type CaseMode uint8
CaseMode controls literal comparison. Regexp case behavior is expressed by the Go regexp itself. Term behavior belongs to the injected Analyzer.
type IncompleteReason ¶
type IncompleteReason uint32
IncompleteReason is a bit set because more than one budget may truncate one query. A zero value means complete.
const ( IncompleteScanLimit IncompleteReason = 1 << iota IncompleteResultLimit IncompleteCandidateLimit IncompleteFallbackDisabled )
func (IncompleteReason) Has ¶
func (r IncompleteReason) Has(reason IncompleteReason) bool
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is permanently bound to one immutable Source revision and one published candidate generation.
func Build ¶
func Build(ctx context.Context, source Source, revision uint64, options IndexOptions) (*Index, error)
Build creates and atomically publishes a complete persistent generation. The caller retains Source ownership.
func BuildOwned ¶
func BuildOwned(ctx context.Context, source OwnedSource, revision uint64, options IndexOptions) (*Index, error)
BuildOwned transfers Source ownership to the returned Index.
func Open ¶
func Open(ctx context.Context, source Source, revision uint64, options IndexOptions) (*Index, error)
Open validates a published generation against the complete immutable Source.
func OpenOrBuild ¶
func OpenOrBuild(ctx context.Context, source Source, revision uint64, options IndexOptions) (*Index, error)
OpenOrBuild opens an exact generation or replaces a missing, stale, corrupt, or analyzer-incompatible cache with a complete rebuild.
func OpenOrBuildOwned ¶
func OpenOrBuildOwned(ctx context.Context, source OwnedSource, revision uint64, options IndexOptions) (*Index, error)
func OpenOwned ¶
func OpenOwned(ctx context.Context, source OwnedSource, revision uint64, options IndexOptions) (*Index, error)
func Rebuild ¶
func Rebuild(ctx context.Context, source Source, previous *Index, changes coordinate.ChangeMap) (*Index, error)
Rebuild publishes the current Source revision. When deterministic block boundaries are unchanged, it clones the immutable previous database and rewrites only blocks whose overlap-inclusive content hash changed. Any unprovable case falls back to a complete Build.
func RebuildOwned ¶
func RebuildOwned(ctx context.Context, source OwnedSource, previous *Index, changes coordinate.ChangeMap) (*Index, error)
func (*Index) CloseContext ¶
CloseContext starts one shared shutdown, cancels admitted queries, and may stop waiting without abandoning database and Source cleanup.
type IndexOptions ¶
type Lineage ¶
type Lineage struct {
// contains filtered or unexported fields
}
Lineage is an opaque identity shared by indexes derived from one trusted Source history. Pointer identity is intentional.
func NewLineage ¶
func NewLineage() *Lineage
type Options ¶
type Options struct {
ReadBufferBytes int64
MaxScannedBytes int64
MaxPatternBytes int
MaxResults int
MaxCandidateBlocks int
// DisableFallback prevents an Index from falling back to Scan when no
// complete candidate plan fits the configured budgets.
DisableFallback bool
// SourceKey is an opaque host value copied into every Match.
SourceKey string
}
Options are hard per-query limits. Zero selects a bounded default.
type OwnedSource ¶
OwnedSource transfers its lifetime to an Index.
type Query ¶
Query is immutable by value. Text is literal text, a Go RE2 pattern, or an analyzer query depending on Kind.
type Report ¶
type Report struct {
Revision uint64
Generation uint64
Matches []Match
Complete bool
Incomplete IncompleteReason
UsedIndex bool
ScannedBytes int64
CandidateBlocks int
}
Report describes both results and the work used to obtain them.
func Scan ¶
func Scan(ctx context.Context, source Source, revision uint64, query Query, options Options) (Report, error)
Scan is the correctness baseline used when no persistent candidate index is available. Literal queries stream through a fixed-size buffer. Regexp queries buffer only the explicitly bounded scanned prefix because Go's RE2 engine does not expose resumable automaton state.
type Stats ¶
type Stats struct {
Revision uint64
Generation uint64
ByteLength int64
BlockCount int
BlockBytes int64
OverlapBytes int64
AnalyzerID string
Directory string
DatabaseBytes int64
ReusedBlocks int
IndexedBlocks int
Closed bool
}
Stats is an immutable view of one published search generation.