search

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const SchemaVersion = "1"

Variables

This section is empty.

Functions

func DetectProjectRoot

func DetectProjectRoot(cwd string) (string, error)

DetectProjectRoot walks upward from cwd looking for a .draft/ directory or a CLAUDE.md file. Returns the first directory containing either marker, or cwd itself if no marker is found.

func FormatResults

func FormatResults(results []SearchResult) string

FormatResults formats search results as markdown with fenced code blocks.

func IndexPath

func IndexPath(projectRoot, overridePath string) (string, error)

IndexPath returns the path to the SQLite database for the given project root. If overridePath is non-empty, it is returned directly (supports --db flag).

func PruneIndexes

func PruneIndexes() ([]string, error)

PruneIndexes scans the cache directory and deletes indexes whose project_root no longer exists on disk.

Types

type FileRow

type FileRow struct {
	ID      int64
	Path    string
	Hash    string
	Mtime   int64
	Indexed int64
}

FileRow represents a row in the files table.

type IndexInfo

type IndexInfo struct {
	ProjectRoot string
	FileCount   int
	SizeBytes   int64
	LastIndexed string
	DBPath      string
}

IndexInfo holds summary info about one index database.

func ListIndexes

func ListIndexes() ([]IndexInfo, error)

ListIndexes returns info about all index databases in the cache directory.

type IndexResult

type IndexResult struct {
	FilesIndexed   int
	FilesSkipped   int
	FilesDeleted   int
	FilesUnchanged int
}

IndexResult reports what happened during an index run.

func Index

func Index(store *Store, projectRoot string, force bool) (*IndexResult, error)

Index walks the project tree and updates both FTS5 indexes incrementally. If force is true, the store is rebuilt from scratch first.

type QueryType

type QueryType int

QueryType classifies a search query.

const (
	QueryNaturalLanguage QueryType = iota
	QuerySubstring
	QueryMixed
)

func ClassifyQuery

func ClassifyQuery(query string) QueryType

ClassifyQuery determines how to route a query.

type SearchResult

type SearchResult struct {
	Path    string
	Score   float64
	Snippet string
}

SearchResult represents a single search hit.

func Search(store *Store, query string, limit int) ([]SearchResult, error)

Search runs a query against the index and returns ranked results.

type StatusInfo

type StatusInfo struct {
	DBPath      string
	ProjectRoot string
	FileCount   int
	LastIndexed string
	SizeBytes   int64
}

StatusInfo holds information for the --status flag.

type Store

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

Store wraps a SQLite database with dual FTS5 indexes.

func OpenStore

func OpenStore(dbPath, projectRoot string) (*Store, error)

OpenStore opens (or creates) the search index database at dbPath. projectRoot is recorded in index_meta for diagnostics and prune.

func (*Store) AllFilePaths

func (s *Store) AllFilePaths() (map[string]int64, error)

AllFilePaths returns all indexed file paths.

func (*Store) Begin

func (s *Store) Begin() (*sql.Tx, error)

Begin starts a new transaction.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database connection.

func (*Store) DB

func (s *Store) DB() *sql.DB

DB exposes the underlying *sql.DB for use by indexer and searcher.

func (*Store) DeleteFTS

func (s *Store) DeleteFTS(tx *sql.Tx, id int64) error

DeleteFTS removes FTS entries for the given file ID from both tables. Reads original content from fts to supply to contentless fts_trigram delete.

func (*Store) DeleteFile

func (s *Store) DeleteFile(tx *sql.Tx, id int64) error

DeleteFile removes a file and its FTS entries. For contentless fts_trigram, we must supply the original content for deletion.

func (*Store) FileCount

func (s *Store) FileCount() (int, error)

FileCount returns the number of indexed files.

func (*Store) ForceRebuild

func (s *Store) ForceRebuild() error

ForceRebuild drops all tables and recreates the schema.

func (*Store) GetFile

func (s *Store) GetFile(path string) (*FileRow, error)

GetFile returns the file row for the given path, or nil if not found.

func (*Store) InsertFTS

func (s *Store) InsertFTS(tx *sql.Tx, id int64, path, content string) error

InsertFTS inserts content into both FTS5 tables for the given file ID.

func (*Store) Meta

func (s *Store) Meta(key string) (string, error)

Meta returns a value from index_meta.

func (*Store) Optimize

func (s *Store) Optimize() error

Optimize runs PRAGMA optimize on the database.

func (*Store) ProjectRoot

func (s *Store) ProjectRoot() string

ProjectRoot returns the project root stored in this store.

func (*Store) UpdateMtime

func (s *Store) UpdateMtime(tx *sql.Tx, id, mtime int64) error

UpdateMtime updates only the mtime for a file (content unchanged).

func (*Store) UpsertFile

func (s *Store) UpsertFile(tx *sql.Tx, path, hash string, mtime int64) (int64, error)

UpsertFile inserts or updates a file row and returns its ID.

Jump to

Keyboard shortcuts

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