Documentation
¶
Overview ¶
Package query implements the QUERY layer: symbol search, graph traversal (callers/callees/impact), and index status/files verbs.
Ported from src/db/queries.ts, src/graph/traversal.ts, src/search/query-parser.ts, src/search/query-utils.ts, and src/bin/codegraph.ts of github.com/colbymchenry/codegraph (MIT).
Public functions accept a *store.Store and return typed structs that marshal to the exact JSON payloads produced by the original CLI's --json flags.
Index ¶
- func BoundedEditDistance(a, b string, maxDist int) int
- func HasExactMatch(s *store.Store, symbol string) (bool, error)
- func IsGeneratedFile(filePath string) bool
- func IsTestFile(filePath string) bool
- func KindBonus(kind model.NodeKind) float64
- func NameMatchBonus(nodeName, query string) float64
- func ScorePathRelevance(filePath, query string, projectNameTokens map[string]struct{}) float64
- func SearchNodes(s *store.Store, rawQuery string, opts SearchOptions) ([]model.SearchResult, error)
- type CalleesResult
- type CallersResult
- type FileInfo
- type ImpactResult
- type IndexInfo
- type ParsedQuery
- type PendingChanges
- type SearchOptions
- type StatusResult
- type SymbolRef
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BoundedEditDistance ¶
BoundedEditDistance computes a bounded Levenshtein distance between a and b. Returns maxDist+1 as soon as distance exceeds maxDist. Mirrors boundedEditDistance from src/search/query-parser.ts.
func HasExactMatch ¶
HasExactMatch reports whether s contains a symbol whose name exactly matches the query (the whole name, or a `.`/`::`-qualified suffix), as opposed to only a fuzzy/substring search hit. Multi-store callers use this to prefer exact-match scopes, so a verb like callers/callees/impact does not leak a substring hit from a scope where the symbol appears only as a substring (e.g. "get" matching "Widget").
func IsGeneratedFile ¶
IsGeneratedFile returns true for files that appear auto-generated. Mirrors isGeneratedFile from src/extraction/generated-detection.ts.
func IsTestFile ¶
IsTestFile checks whether a file path looks like a test file. Mirrors isTestFile from src/search/query-utils.ts.
func KindBonus ¶
KindBonus returns the relevance bonus for a node kind. Mirrors kindBonus from src/search/query-utils.ts.
func NameMatchBonus ¶
NameMatchBonus returns a score bonus when the node name matches the query. Mirrors nameMatchBonus from src/search/query-utils.ts.
func ScorePathRelevance ¶
ScorePathRelevance returns a relevance score for a file path against a query. Mirrors scorePathRelevance from src/search/query-utils.ts. projectNameTokens can be nil (no down-weighting).
func SearchNodes ¶
func SearchNodes(s *store.Store, rawQuery string, opts SearchOptions) ([]model.SearchResult, error)
SearchNodes runs the multi-strategy search pipeline (FTS5 → LIKE → fuzzy, with exact-name supplement and multi-signal rescoring). Mirrors QueryBuilder.searchNodes from src/db/queries.ts.
Types ¶
type CalleesResult ¶
CalleesResult is the JSON payload for `codegraph callees <symbol>`.
type CallersResult ¶
CallersResult is the JSON payload for `codegraph callers <symbol>`.
type FileInfo ¶
type FileInfo struct {
Path string `json:"path"`
Language model.Language `json:"language"`
NodeCount int `json:"nodeCount"`
Size int64 `json:"size"`
}
FileInfo is one entry in the `files` JSON array.
type ImpactResult ¶
type ImpactResult struct {
Symbol string `json:"symbol"`
Depth int `json:"depth"`
NodeCount int `json:"nodeCount"`
EdgeCount int `json:"edgeCount"`
Affected []SymbolRef `json:"affected"`
}
ImpactResult is the JSON payload for `codegraph impact <symbol>`.
type IndexInfo ¶
type IndexInfo struct {
BuiltWithVersion string `json:"builtWithVersion"`
BuiltWithExtractionVersion int `json:"builtWithExtractionVersion"`
CurrentExtractionVersion int `json:"currentExtractionVersion"`
ReindexRecommended bool `json:"reindexRecommended"`
}
IndexInfo mirrors the `index` block of the status payload.
type ParsedQuery ¶
type ParsedQuery struct {
// Free-text portion to feed to FTS / LIKE. May be empty.
Text string
// kind: filters (OR'd). Empty when none specified.
Kinds []model.NodeKind
// lang:/language: filters (OR'd). Empty when none specified.
Languages []model.Language
// path: filters (OR'd, case-insensitive substring of file_path).
PathFilters []string
// name: filters (OR'd, case-insensitive substring of node.name).
NameFilters []string
}
ParsedQuery holds the result of parsing a raw search string. Mirrors ParsedQuery from src/search/query-parser.ts.
func ParseQuery ¶
func ParseQuery(raw string) ParsedQuery
ParseQuery parses a raw query string into structured filters + remaining text. Mirrors parseQuery from src/search/query-parser.ts. Always returns a value; never panics.
type PendingChanges ¶
type PendingChanges struct {
Added int `json:"added"`
Modified int `json:"modified"`
Removed int `json:"removed"`
}
PendingChanges mirrors the pendingChanges field in the status payload.
type SearchOptions ¶
type SearchOptions struct {
Limit int
Offset int
Kinds []model.NodeKind
Languages []model.Language
}
SearchOptions controls result set size and filtering for SearchNodes.
type StatusResult ¶
type StatusResult struct {
Initialized bool `json:"initialized"`
Version string `json:"version"`
ProjectPath string `json:"projectPath"`
IndexPath string `json:"indexPath"`
LastIndexed string `json:"lastIndexed"`
FileCount int `json:"fileCount"`
NodeCount int `json:"nodeCount"`
EdgeCount int `json:"edgeCount"`
DBSizeBytes int64 `json:"dbSizeBytes"`
Backend string `json:"backend"`
JournalMode string `json:"journalMode"`
NodesByKind map[model.NodeKind]int `json:"nodesByKind"`
Languages []string `json:"languages"`
PendingChanges PendingChanges `json:"pendingChanges"`
WorktreeMismatch any `json:"worktreeMismatch"`
Index IndexInfo `json:"index"`
}
StatusResult is the JSON payload for `codegraph status`.