indexer

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmitContainment

func EmitContainment(ctx context.Context, e Emitter, parentID, childID string) error

EmitContainment creates bidirectional containment edges using any Emitter: - contains: parentID → childID (structural containment) - contained_by: childID → parentID (inverse) Use for physical/structural hierarchies (directories, nested structures).

func EmitOwnership

func EmitOwnership(ctx context.Context, e Emitter, ownerID, ownedID string) error

EmitOwnership creates bidirectional ownership edges using any Emitter: - has: ownerID → ownedID (logical ownership) - belongs_to: ownedID → ownerID (inverse) Use when the child cannot exist without the parent (repo→branch, doc→section).

func GetScheme

func GetScheme(uri string) string

GetScheme extracts the scheme from a URI. Returns empty string if the URI is invalid or has no scheme.

Types

type CollectingEmitter

type CollectingEmitter struct {
	Nodes []*graph.Node
	Edges []*graph.Edge
}

CollectingEmitter collects nodes and edges for later processing. Useful for testing or batch operations.

func (*CollectingEmitter) EmitContainment

func (e *CollectingEmitter) EmitContainment(ctx context.Context, parentID, childID string) error

EmitContainment creates bidirectional containment edges for testing.

func (*CollectingEmitter) EmitEdge

func (e *CollectingEmitter) EmitEdge(ctx context.Context, edge *graph.Edge) error

func (*CollectingEmitter) EmitNode

func (e *CollectingEmitter) EmitNode(ctx context.Context, node *graph.Node) error

func (*CollectingEmitter) EmitOwnership

func (e *CollectingEmitter) EmitOwnership(ctx context.Context, ownerID, ownedID string) error

EmitOwnership creates bidirectional ownership edges for testing.

type Context

type Context struct {
	// Root is the URI where indexing started (defines the boundary).
	Root string

	// Generation is the current index generation for staleness tracking.
	Generation string

	// Graph provides access to the existing graph state.
	Graph *graph.Graph

	// Emitter is where discovered nodes and edges should be emitted.
	Emitter Emitter

	// Progress is an optional channel for reporting indexing progress.
	// If nil, progress reporting is disabled.
	Progress chan<- progress.Event

	// Events is an optional channel for broadcasting indexer events.
	// Other indexers can subscribe to these events to react dynamically.
	// If nil, event broadcasting is disabled.
	Events chan<- Event

	// TriggerEvent is the event that triggered this indexer invocation.
	// Nil for direct invocations (primary indexers).
	// Set when the indexer is triggered by an event subscription.
	TriggerEvent *Event
	// contains filtered or unexported fields
}

Context provides the execution environment for an indexer.

func (*Context) AddDirsIndexed

func (c *Context) AddDirsIndexed(n int)

AddDirsIndexed atomically adds n to the count of indexed directories.

func (*Context) AddFilesIndexed

func (c *Context) AddFilesIndexed(n int)

AddFilesIndexed atomically adds n to the count of indexed files.

func (*Context) AddNodesDeleted

func (c *Context) AddNodesDeleted(n int)

AddNodesDeleted atomically adds n to the count of deleted nodes.

func (*Context) AddReposIndexed

func (c *Context) AddReposIndexed(n int)

AddReposIndexed atomically adds n to the count of indexed repositories.

func (*Context) DirsIndexed

func (c *Context) DirsIndexed() int64

DirsIndexed returns the total number of directories indexed.

func (*Context) FilesIndexed

func (c *Context) FilesIndexed() int64

FilesIndexed returns the total number of files indexed.

func (*Context) InBounds

func (c *Context) InBounds(uri string) bool

InBounds returns true if the given URI is within the root boundary. This is used to prevent indexers from traversing outside their scope.

func (*Context) NodesDeleted

func (c *Context) NodesDeleted() int64

NodesDeleted returns the total number of nodes deleted during cleanup.

func (*Context) ReposIndexed

func (c *Context) ReposIndexed() int64

ReposIndexed returns the total number of repositories indexed.

type CountingEmitter

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

CountingEmitter wraps an Emitter and tracks node counts by type in the Context.

func NewCountingEmitter

func NewCountingEmitter(inner Emitter, ictx *Context) *CountingEmitter

NewCountingEmitter creates an emitter that wraps inner and increments counters in ictx based on emitted node types.

func (*CountingEmitter) EmitEdge

func (e *CountingEmitter) EmitEdge(ctx context.Context, edge *graph.Edge) error

func (*CountingEmitter) EmitNode

func (e *CountingEmitter) EmitNode(ctx context.Context, node *graph.Node) error

type Emitter

type Emitter interface {
	// EmitNode adds or updates a node in the graph.
	EmitNode(ctx context.Context, node *graph.Node) error

	// EmitEdge adds or updates an edge in the graph.
	EmitEdge(ctx context.Context, edge *graph.Edge) error
}

Emitter receives discovered nodes and edges during indexing.

type Event

type Event struct {
	// Type is the event type.
	Type EventType

	// URI is the full URI of the entry.
	URI string

	// Path is the filesystem path (if applicable).
	Path string

	// Name is the basename of the entry.
	Name string

	// NodeType is the type of node (e.g., "fs:dir", "fs:file").
	NodeType string

	// NodeID is the ID of the emitted node (empty if entry was skipped/ignored).
	NodeID string

	// Node is the node that was created (if available).
	// This allows subscribers to modify the node without a DB round-trip.
	Node *graph.Node
}

Event represents an indexing event that other indexers can subscribe to.

type EventType

type EventType int

EventType represents the type of indexing event.

const (
	// EventEntryVisited is emitted when an entry (file, dir, etc.) is visited.
	EventEntryVisited EventType = iota

	// EventNodeDeleting is emitted when a node is about to be deleted.
	// Subscribers can react by cleaning up related nodes.
	EventNodeDeleting
)

type GraphEmitter

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

GraphEmitter emits nodes and edges directly to a graph.

func NewGraphEmitter

func NewGraphEmitter(g *graph.Graph, generation string) *GraphEmitter

NewGraphEmitter creates an emitter that writes to the given graph.

func (*GraphEmitter) EmitContainment

func (e *GraphEmitter) EmitContainment(ctx context.Context, parentID, childID string) error

EmitContainment creates bidirectional containment edges: - contains: parentID → childID (structural containment) - contained_by: childID → parentID (inverse) Use for physical/structural hierarchies (directories, nested structures).

func (*GraphEmitter) EmitEdge

func (e *GraphEmitter) EmitEdge(ctx context.Context, edge *graph.Edge) error

func (*GraphEmitter) EmitNode

func (e *GraphEmitter) EmitNode(ctx context.Context, node *graph.Node) error

func (*GraphEmitter) EmitOwnership

func (e *GraphEmitter) EmitOwnership(ctx context.Context, ownerID, ownedID string) error

EmitOwnership creates bidirectional ownership edges: - has: ownerID → ownedID (logical ownership) - belongs_to: ownedID → ownerID (inverse) Use when the child cannot exist without the parent (repo→branch, doc→section).

type Indexer

type Indexer interface {
	// Name returns the indexer identifier (e.g., "fs", "git", "golang").
	Name() string

	// Schemes returns the URI schemes this indexer handles (e.g., ["file"], ["git"]).
	Schemes() []string

	// Handles returns true if this indexer can process the given URI.
	Handles(uri string) bool

	// Subscriptions returns the events this indexer subscribes to.
	// Return nil or empty slice if this indexer doesn't subscribe to events
	// (i.e., it's a primary indexer triggered directly, not by events).
	Subscriptions() []Subscription

	// Index indexes starting from the root URI in the context.
	Index(ctx context.Context, ictx *Context) error

	// HandleEvent processes an event from another indexer.
	// Called when an event matches one of this indexer's subscriptions.
	// The event includes the Node so implementations can avoid DB round-trips.
	HandleEvent(ctx context.Context, ictx *Context, event Event) error
}

Indexer discovers and indexes nodes/edges from a specific domain.

type PostIndexer

type PostIndexer interface {
	Indexer
	// PostIndex is called after all indexers complete their Index() pass.
	PostIndex(ctx context.Context, ictx *Context) error
}

PostIndexer is an optional interface for indexers that need a post-processing stage. This is called after all indexers have completed their initial Index() pass, allowing deferred resolution (e.g., resolving local links to files indexed later).

type Registry

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

Registry holds registered indexers and routes URIs to them.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new indexer registry.

func (*Registry) All

func (r *Registry) All() []Indexer

All returns all registered indexers.

func (*Registry) ByName added in v0.6.0

func (r *Registry) ByName(name string) Indexer

ByName returns the indexer with the given name, or nil if not found.

func (*Registry) ForScheme

func (r *Registry) ForScheme(scheme string) []Indexer

ForScheme returns all indexers that handle the given URI scheme.

func (*Registry) ForURI

func (r *Registry) ForURI(uri string) Indexer

ForURI returns the first indexer that can handle the given URI. Returns nil if no indexer handles the URI.

func (*Registry) Register

func (r *Registry) Register(idx Indexer)

Register adds an indexer to the registry.

func (*Registry) SubscribersFor

func (r *Registry) SubscribersFor(event Event) []Indexer

SubscribersFor returns all indexers that have a subscription matching the event.

type Subscription

type Subscription struct {
	// EventType is the type of event to subscribe to.
	EventType EventType

	// NodeType filters by node type (empty = all types).
	NodeType string

	// Name filters by exact entry name match (empty = all names).
	Name string

	// Pattern filters by glob pattern on the entry name (e.g., "*.md", "test_*.go").
	// Empty means no pattern filtering.
	Pattern string

	// Extensions filters by file extensions (e.g., []string{".md", ".markdown"}).
	// Empty means no extension filtering.
	Extensions []string
}

Subscription defines what events an indexer wants to receive.

func (Subscription) Matches

func (s Subscription) Matches(e Event) bool

Matches returns true if the event matches this subscription.

Directories

Path Synopsis
Package embeddings provides the Provider interface and built-in implementations for generating vector embeddings from text.
Package embeddings provides the Provider interface and built-in implementations for generating vector embeddings from text.
git
commitparser
Package commitparser implements a lenient parser for Conventional Commits (https://www.conventionalcommits.org/).
Package commitparser implements a lenient parser for Conventional Commits (https://www.conventionalcommits.org/).
Package golang provides an indexer for Go modules and packages.
Package golang provides an indexer for Go modules and packages.
Package project provides an indexer for detecting project types from manifest files.
Package project provides an indexer for detecting project types from manifest files.
Package todo indexes TODO/FIXME/HACK/XXX/NOTE annotation comments from source files, emitting one code:todo graph node per matched annotation.
Package todo indexes TODO/FIXME/HACK/XXX/NOTE annotation comments from source files, emitting one code:todo graph node per matched annotation.

Jump to

Keyboard shortcuts

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