Documentation
¶
Index ¶
- type ContentIndex
- func (ci *ContentIndex) Clear() error
- func (ci *ContentIndex) Close() error
- func (ci *ContentIndex) DocumentCount() uint64
- func (ci *ContentIndex) GetFileContent(relativePath string) (string, bool)
- func (ci *ContentIndex) IndexFile(relativePath string, content string, language string) error
- func (ci *ContentIndex) RemoveFile(relativePath string)
- func (ci *ContentIndex) Search(options SearchOptions) ([]ContentSearchResult, int, bool, error)
- type ContentSearchResult
- type FileIndex
- func (fi *FileIndex) AddFile(file *IndexedFile)
- func (fi *FileIndex) AllFiles() []*IndexedFile
- func (fi *FileIndex) Clear()
- func (fi *FileIndex) FileCount() int
- func (fi *FileIndex) GetFile(relativePath string) *IndexedFile
- func (fi *FileIndex) LanguageCounts() map[string]int
- func (fi *FileIndex) RemoveFile(relativePath string)
- func (fi *FileIndex) SearchByGlob(pattern string, maxResults int) ([]FileSearchResult, error)
- func (fi *FileIndex) TotalSizeBytes() int64
- type FileSearchResult
- type Hunk
- type IndexedFile
- type SearchOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContentIndex ¶
type ContentIndex struct {
// contains filtered or unexported fields
}
ContentIndex provides exact, grep-style search over file contents held in memory. All content is stored in RAM and queries scan the stored lines directly, so results have full substring and regex recall (no tokenizer false negatives).
func NewContentIndex ¶
func NewContentIndex() (*ContentIndex, error)
NewContentIndex creates a new empty in-memory content index. The error return value is kept for API stability; it is always nil.
func (*ContentIndex) Clear ¶
func (ci *ContentIndex) Clear() error
Clear removes all files from the index. The error return value is kept for API stability; it is always nil.
func (*ContentIndex) Close ¶
func (ci *ContentIndex) Close() error
Close releases resources. The in-memory index has nothing to release; kept for API stability.
func (*ContentIndex) DocumentCount ¶
func (ci *ContentIndex) DocumentCount() uint64
DocumentCount returns the number of files in the content index.
func (*ContentIndex) GetFileContent ¶
func (ci *ContentIndex) GetFileContent(relativePath string) (string, bool)
GetFileContent returns the raw content of an indexed file. Returns the content and true if found, or empty string and false if not indexed.
func (*ContentIndex) IndexFile ¶
func (ci *ContentIndex) IndexFile(relativePath string, content string, language string) error
IndexFile adds or updates a file's content in the index. The error return value is kept for API stability; it is always nil.
func (*ContentIndex) RemoveFile ¶
func (ci *ContentIndex) RemoveFile(relativePath string)
RemoveFile removes a file from the index.
func (*ContentIndex) Search ¶
func (ci *ContentIndex) Search(options SearchOptions) ([]ContentSearchResult, int, bool, error)
Search scans all indexed file contents line by line and returns grep-equivalent results. Query format:
- Plain text: literal substring match, case-insensitive by default
- "quoted text": exact literal match, always case-sensitive
- /regex/: Go (RE2) regular expression matched per line, case-insensitive by default
The boolean return value reports whether the file limit (MaxResults) was reached while more matching files remained.
type ContentSearchResult ¶
type ContentSearchResult struct {
RelativePath string
MatchCount int // total matching lines in the file (before the per-file display cap)
Hunks []Hunk // context-merged display hunks, capped at MaxMatchesPerFile matches
}
ContentSearchResult holds all matches within one file.
type FileIndex ¶
type FileIndex struct {
// contains filtered or unexported fields
}
FileIndex maintains an in-memory index of file paths for fast glob-based searching. It uses a map for O(1) path lookups and a sorted slice for glob iteration.
func NewFileIndex ¶
func NewFileIndex() *FileIndex
NewFileIndex creates a new empty file path index.
func (*FileIndex) AddFile ¶
func (fi *FileIndex) AddFile(file *IndexedFile)
AddFile adds or updates a file in the index.
func (*FileIndex) AllFiles ¶
func (fi *FileIndex) AllFiles() []*IndexedFile
AllFiles returns all indexed files in sorted order. Use with caution on large indexes.
func (*FileIndex) GetFile ¶
func (fi *FileIndex) GetFile(relativePath string) *IndexedFile
GetFile returns the IndexedFile for a given relative path, or nil if not found.
func (*FileIndex) LanguageCounts ¶
LanguageCounts returns a map of language -> file count for all indexed files.
func (*FileIndex) RemoveFile ¶
RemoveFile removes a file from the index by its relative path.
func (*FileIndex) SearchByGlob ¶
func (fi *FileIndex) SearchByGlob(pattern string, maxResults int) ([]FileSearchResult, error)
SearchByGlob returns files matching a doublestar glob pattern. The pattern is matched against relative paths (forward slashes).
func (*FileIndex) TotalSizeBytes ¶
TotalSizeBytes returns the total size of all indexed files.
type FileSearchResult ¶
type FileSearchResult struct {
File *IndexedFile
}
SearchResult holds a file match from a glob search.
type Hunk ¶ added in v0.6.0
type Hunk struct {
StartLine int // 1-based line number of Lines[0]
Lines []string
IsMatch []bool // parallel to Lines; true for lines that match the query
}
Hunk is a contiguous block of lines containing one or more matches plus context. Overlapping or adjacent match contexts are merged into a single hunk.
type IndexedFile ¶
type IndexedFile struct {
Path string // Absolute file path
RelativePath string // Path relative to project root (forward slashes)
Language string // Detected programming language
SizeBytes int64 // File size in bytes
ModTime time.Time // Last modification time
LineCount int // Number of lines in the file
}
IndexedFile represents a file that has been indexed. Used by both the file path index and the content index.
type SearchOptions ¶
type SearchOptions struct {
Query string
FilePath string // Exact relative path to restrict search to a single file (overrides FileGlob)
FileGlob string
MaxResults int // max number of files returned (default 50)
ContextLines int // context lines before and after each match
MaxMatchesPerFile int // max matches rendered per file (default 10)
CaseSensitive bool // case-sensitive matching for plain text and regex queries
}
SearchOptions configures a content search.