Documentation
¶
Overview ¶
Package index wraps Bleve: schema definition, Open/Create, and the Upsert/Delete/Stats surface used by sync, query, and MCP layers.
Index ¶
Constants ¶
const DefaultIdleTimeout = 30 * time.Second
DefaultIdleTimeout is how long LazyIndex waits with zero refs before closing the underlying handle and releasing the OS file lock.
const DefaultRetryBudget = 30 * time.Second
DefaultRetryBudget caps how long Acquire will keep retrying when the underlying open hits ErrIndexLocked (i.e. another process holds the writer lock).
const SchemaVersion = 1
SchemaVersion is bumped when the field mapping changes in a backwards-incompatible way. sync compares it against meta.json and rebuilds the index on mismatch.
Variables ¶
var ErrIndexLocked = errors.New("index is locked by another process")
ErrIndexLocked is returned when the bbolt file lock cannot be acquired within openLockTimeout. Most commonly this means another codesearch process (typically the `serve` MCP server, or a parallel `sync`) is holding an incompatible lock.
Functions ¶
func BuildMapping ¶
func BuildMapping() *mapping.IndexMappingImpl
BuildMapping returns the Bleve index mapping. The default document mapping has Dynamic enabled so any frontmatter key becomes an indexed field automatically; the named fields below are pinned so they have consistent analyzers regardless of what shows up in dynamic mode.
Types ¶
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index wraps bleve.Index with the Upsert/Delete/Iterate surface that the sync, query, and MCP layers consume.
func Open ¶
Open opens an existing index at path for read/write access. If the underlying bbolt lock cannot be acquired within openLockTimeout, returns a wrapped ErrIndexLocked.
func OpenReadOnly ¶
OpenReadOnly opens an existing index at path with read-only semantics (shared lock). Multiple read-only handles can coexist; a writer is still blocked while any read-only handle is open.
func (*Index) Iterate ¶
Iterate calls fn once per indexed document, paginating internally. The fn must return nil to continue; any error aborts iteration.
type LazyIndex ¶
type LazyIndex struct {
// contains filtered or unexported fields
}
LazyIndex is a refcounted, idle-closing wrapper around a read-only *Index. The MCP server uses it so concurrent tool requests share a single open handle while sync/query CLI invocations can still acquire the OS file lock during idle windows.
Concurrent Acquire calls are coalesced: the first opens the handle, the rest wait. Once all refs are released, an idle timer closes the handle so other processes are free to write.
func NewLazy ¶
NewLazy constructs a LazyIndex over path. idle and retry default to DefaultIdleTimeout and DefaultRetryBudget when zero.