index

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 9 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 full-text search over file contents using Bleve in-memory index.

func NewContentIndex

func NewContentIndex() (*ContentIndex, error)

NewContentIndex creates a new in-memory Bleve content index.

func (*ContentIndex) Clear

func (ci *ContentIndex) Clear() error

Clear removes all documents and recreates the index.

func (*ContentIndex) Close

func (ci *ContentIndex) Close() error

Close closes the Bleve index.

func (*ContentIndex) DocumentCount

func (ci *ContentIndex) DocumentCount() uint64

DocumentCount returns the number of documents in the Bleve 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 search index.

func (*ContentIndex) RemoveFile

func (ci *ContentIndex) RemoveFile(relativePath string)

RemoveFile removes a file from the search index.

func (*ContentIndex) Search

func (ci *ContentIndex) Search(options SearchOptions) ([]ContentSearchResult, int, error)

Search performs a full-text search across all indexed files. Query format:

  • Plain text: match query (word-level matching)
  • "quoted text": phrase query (exact phrase match)
  • /regex/: regexp query

type ContentSearchResult

type ContentSearchResult struct {
	RelativePath string
	Matches      []LineMatch
}

ContentSearchResult holds a search match within a 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 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 LineMatch

type LineMatch struct {
	LineNumber int
	LineText   string
	// Context lines before and after the match
	ContextBefore []string
	ContextAfter  []string
}

LineMatch represents a single line match within a file.

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
	ContextLines int
}

SearchOptions configures a content search.

Jump to

Keyboard shortcuts

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