index

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

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) Clear

func (fi *FileIndex) Clear()

Clear removes all files from the index.

func (*FileIndex) FileCount

func (fi *FileIndex) FileCount() int

FileCount returns the number of indexed files.

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

func (fi *FileIndex) LanguageCounts() map[string]int

LanguageCounts returns a map of language -> file count for all indexed files.

func (*FileIndex) RemoveFile

func (fi *FileIndex) RemoveFile(relativePath string)

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

func (fi *FileIndex) TotalSizeBytes() int64

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.

Jump to

Keyboard shortcuts

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