search

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileLock added in v0.4.1

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

FileLock represents a file-based lock for process synchronization

func NewFileLock added in v0.4.1

func NewFileLock(lockPath string, opts *FileLockOptions) (*FileLock, error)

NewFileLock creates a new file lock instance

func (*FileLock) GetLockInfo added in v0.4.1

func (fl *FileLock) GetLockInfo() (*LockInfo, error)

GetLockInfo returns information about the current lock holder

func (*FileLock) IsLocked added in v0.4.1

func (fl *FileLock) IsLocked() bool

IsLocked returns whether the lock is currently held

func (*FileLock) Lock added in v0.4.1

func (fl *FileLock) Lock(ctx context.Context) error

Lock acquires the file lock with timeout

func (*FileLock) TryLock added in v0.4.1

func (fl *FileLock) TryLock() error

TryLock attempts to acquire the lock without blocking

func (*FileLock) Unlock added in v0.4.1

func (fl *FileLock) Unlock() error

Unlock releases the file lock

type FileLockOptions added in v0.4.1

type FileLockOptions struct {
	Timeout   time.Duration
	Exclusive bool
	CreateDir bool
}

FileLockOptions configures file lock behavior

type FuzzySearchEngine

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

FuzzySearchEngine provides fuzzy search capabilities using Bleve

func NewFuzzySearchEngine

func NewFuzzySearchEngine(indexPath string) *FuzzySearchEngine

NewFuzzySearchEngine creates a new fuzzy search engine

func (*FuzzySearchEngine) Close

func (f *FuzzySearchEngine) Close() error

Close closes the search index and releases resources

func (*FuzzySearchEngine) DeleteCommand

func (f *FuzzySearchEngine) DeleteCommand(sessionID string, timestamp int64) error

DeleteCommand removes a command from the search index

func (*FuzzySearchEngine) GetIndexStats

func (f *FuzzySearchEngine) GetIndexStats() (map[string]interface{}, error)

GetIndexStats returns statistics about the search index

func (*FuzzySearchEngine) IndexCommand

func (f *FuzzySearchEngine) IndexCommand(record *storage.CommandRecord) error

IndexCommand adds or updates a command record in the search index

func (*FuzzySearchEngine) IndexCommands

func (f *FuzzySearchEngine) IndexCommands(records []*storage.CommandRecord) error

IndexCommands adds multiple command records to the search index in batch

func (*FuzzySearchEngine) Initialize

func (f *FuzzySearchEngine) Initialize() error

Initialize sets up the Bleve index with optimized mapping for command search

func (*FuzzySearchEngine) RebuildIndex

func (f *FuzzySearchEngine) RebuildIndex(records []*storage.CommandRecord) error

RebuildIndex rebuilds the entire search index from provided records

func (*FuzzySearchEngine) Search

func (f *FuzzySearchEngine) Search(searchQuery string, opts *FuzzySearchOptions) ([]*FuzzySearchResult, error)

Search performs a fuzzy search with the given query and options

type FuzzySearchOptions

type FuzzySearchOptions struct {
	// Fuzzy matching options
	Fuzziness       int     `json:"fuzziness"`      // Edit distance (0-2)
	PrefixLength    int     `json:"prefix_length"`  // Number of prefix characters that must match exactly
	BoostRecent     float64 `json:"boost_recent"`   // Score boost for recent commands (last 24h)
	BoostFrequent   float64 `json:"boost_frequent"` // Score boost for frequently used commands
	BoostExactMatch float64 `json:"boost_exact"`    // Score boost for exact matches
	BoostPrefix     float64 `json:"boost_prefix"`   // Score boost for prefix matches

	// Search constraints
	MinScore       float64 `json:"min_score"`        // Minimum relevance score to include in results
	IncludeWorkDir bool    `json:"include_work_dir"` // Include working directory in search
	IncludeGitInfo bool    `json:"include_git_info"` // Include git branch/repo in search
	AnalyzeCommand bool    `json:"analyze_command"`  // Use text analysis on commands

	// Performance options
	MaxCandidates int           `json:"max_candidates"` // Maximum candidates to evaluate
	SearchTimeout time.Duration `json:"search_timeout"` // Maximum time for search operation
}

FuzzySearchOptions controls fuzzy search behavior

type FuzzySearchResult

type FuzzySearchResult struct {
	Record      *storage.CommandRecord `json:"record"`
	Score       float64                `json:"score"`
	Explanation map[string]float64     `json:"explanation,omitempty"` // Score breakdown
	Fragments   map[string][]string    `json:"fragments,omitempty"`   // Highlighted text fragments
}

FuzzySearchResult represents a search result with scoring information

type LockInfo added in v0.4.1

type LockInfo struct {
	Path      string
	PID       int
	Exclusive bool
	Acquired  time.Time
}

LockInfo contains information about a file lock

type SearchIndexLock added in v0.4.1

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

SearchIndexLock is a specialized lock for search index operations

func NewSearchIndexLock added in v0.4.1

func NewSearchIndexLock(indexPath string) (*SearchIndexLock, error)

NewSearchIndexLock creates a new search index lock

func (*SearchIndexLock) Cleanup added in v0.4.1

func (sil *SearchIndexLock) Cleanup() error

Cleanup releases all locks

func (*SearchIndexLock) Lock added in v0.4.1

func (sil *SearchIndexLock) Lock(ctx context.Context) error

Lock acquires a write lock (exclusive)

func (*SearchIndexLock) RLock added in v0.4.1

func (sil *SearchIndexLock) RLock(ctx context.Context) error

RLock acquires a read lock (uses exclusive lock for simplicity)

func (*SearchIndexLock) RUnlock added in v0.4.1

func (sil *SearchIndexLock) RUnlock() error

RUnlock releases a read lock

func (*SearchIndexLock) Unlock added in v0.4.1

func (sil *SearchIndexLock) Unlock() error

Unlock releases a write lock

type SearchOptions

type SearchOptions struct {
	EnableCache       bool
	DefaultLimit      int
	DefaultMaxBatches int
	DefaultTimeout    time.Duration
	WarmupCache       bool
	EnableFuzzySearch bool
	FuzzyIndexPath    string
	RebuildFuzzyIndex bool
}

SearchOptions provides service-level configuration

type SearchRequest

type SearchRequest struct {
	// Query parameters
	Query  string `json:"query"`
	Limit  int    `json:"limit"`
	Offset int    `json:"offset"`

	// Filter parameters
	WorkingDir string     `json:"working_dir"`
	Hostname   string     `json:"hostname"`
	SessionID  string     `json:"session_id"`
	ExitCode   *int       `json:"exit_code"`
	Since      *time.Time `json:"since"`
	Until      *time.Time `json:"until"`

	// Tag filtering
	Tags        []string `json:"tags,omitempty"`         // Filter by tag names
	ExcludeTags []string `json:"exclude_tags,omitempty"` // Exclude commands with these tags
	TagMode     string   `json:"tag_mode"`               // "any" or "all"

	// Search options
	CaseSensitive  bool `json:"case_sensitive"`
	ExactMatch     bool `json:"exact_match"`
	IncludeGit     bool `json:"include_git"`
	OnlySuccessful bool `json:"only_successful"`

	// Fuzzy search options
	UseFuzzySearch bool                `json:"use_fuzzy_search"`
	FuzzyOptions   *FuzzySearchOptions `json:"fuzzy_options,omitempty"`

	// Performance options
	UseCache   bool          `json:"use_cache"`
	MaxBatches int           `json:"max_batches"`
	Timeout    time.Duration `json:"timeout"`
}

SearchRequest contains search parameters

type SearchResponse

type SearchResponse struct {
	// Results
	Records      []*storage.CommandRecord `json:"records"`
	TotalMatches int                      `json:"total_matches"`

	// Performance metrics
	SearchTime    time.Duration `json:"search_time"`
	FromCache     int           `json:"from_cache"`
	FromBatches   int           `json:"from_batches"`
	CacheHitRatio float64       `json:"cache_hit_ratio"`

	// Fuzzy search metrics
	UsedFuzzySearch bool      `json:"used_fuzzy_search"`
	FuzzyScores     []float64 `json:"fuzzy_scores,omitempty"`
	MaxFuzzyScore   float64   `json:"max_fuzzy_score,omitempty"`
	MinFuzzyScore   float64   `json:"min_fuzzy_score,omitempty"`

	// Pagination
	HasMore    bool `json:"has_more"`
	NextOffset int  `json:"next_offset"`

	// Query info
	Query          string                 `json:"query"`
	AppliedFilters map[string]interface{} `json:"applied_filters"`
}

SearchResponse contains search results and metadata

type SearchService

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

SearchService provides high-level search functionality using the hybrid cache

func NewSearchService

func NewSearchService(cache *cache.Cache, storage *securestorage.SecureStorage, cfg *config.Config) *SearchService

NewSearchService creates a new search service

func (*SearchService) CheckAndRebuildStaleIndex added in v0.2.0

func (s *SearchService) CheckAndRebuildStaleIndex() error

CheckAndRebuildStaleIndex checks if the fuzzy search index is stale and rebuilds it if needed

func (*SearchService) Close

func (s *SearchService) Close() error

Close shuts down the search service

func (*SearchService) GetCacheStats

func (s *SearchService) GetCacheStats() *cache.CacheStats

GetCacheStats returns cache performance statistics

func (*SearchService) GetFuzzySearchStats

func (s *SearchService) GetFuzzySearchStats() (map[string]interface{}, error)

GetFuzzySearchStats returns fuzzy search engine statistics

func (*SearchService) GetStats

func (s *SearchService) GetStats() *SearchStats

GetStats returns search performance statistics

func (*SearchService) IndexCommand

func (s *SearchService) IndexCommand(record *storage.CommandRecord) error

IndexCommand adds a command to the fuzzy search index

func (*SearchService) Initialize

func (s *SearchService) Initialize(opts *SearchOptions) error

Initialize sets up the search service

func (*SearchService) IsFuzzyReady added in v0.4.1

func (s *SearchService) IsFuzzyReady() bool

IsFuzzyReady returns whether fuzzy search is ready

func (*SearchService) QuickSearch

func (s *SearchService) QuickSearch(query string, limit int) ([]*storage.CommandRecord, error)

QuickSearch provides a simple interface for quick searches

func (*SearchService) RefreshCache

func (s *SearchService) RefreshCache() error

RefreshCache refreshes the underlying cache

func (*SearchService) Search

func (s *SearchService) Search(req *SearchRequest) (*SearchResponse, error)

Search performs a search operation

func (*SearchService) SearchByDirectory

func (s *SearchService) SearchByDirectory(directory string, limit int) ([]*storage.CommandRecord, error)

SearchByDirectory searches for commands in a specific directory

func (*SearchService) SearchRecent

func (s *SearchService) SearchRecent(query string, since time.Duration) ([]*storage.CommandRecord, error)

SearchRecent searches for recent commands matching the query

type SearchStats

type SearchStats struct {
	TotalSearches     int64         `json:"total_searches"`
	CacheHits         int64         `json:"cache_hits"`
	CacheMisses       int64         `json:"cache_misses"`
	AverageTime       time.Duration `json:"average_time"`
	LastSearchTime    time.Time     `json:"last_search_time"`
	TotalResultsFound int64         `json:"total_results_found"`
}

SearchStats tracks search performance metrics

type SearchableCommandRecord

type SearchableCommandRecord struct {
	ID         string    `json:"id"`
	DatabaseID int64     `json:"database_id"` // Original database record ID
	Command    string    `json:"command"`
	WorkingDir string    `json:"working_dir"`
	Hostname   string    `json:"hostname"`
	SessionID  string    `json:"session_id"`
	GitBranch  string    `json:"git_branch,omitempty"`
	GitRoot    string    `json:"git_root,omitempty"`
	User       string    `json:"user,omitempty"`
	Shell      string    `json:"shell,omitempty"`
	Note       string    `json:"note,omitempty"` // User note for the command
	Tags       []string  `json:"tags,omitempty"` // Command tags
	ExitCode   int       `json:"exit_code"`
	Duration   int64     `json:"duration_ms"`
	Timestamp  time.Time `json:"timestamp"`
	Success    bool      `json:"success"`
	Recent     bool      `json:"recent"`   // Commands from last 24h
	Frequent   bool      `json:"frequent"` // Frequently used commands
}

SearchableCommandRecord represents a command record optimized for search indexing

type TimeFilter

type TimeFilter struct {
	Since         *time.Time
	Until         *time.Time
	OriginalQuery string // Query with time expressions removed
	HasTimeFilter bool
}

TimeFilter represents parsed time constraints from a search query

func (*TimeFilter) FormatTimeFilter

func (tf *TimeFilter) FormatTimeFilter() string

FormatTimeFilter returns a human-readable description of the time filter

type TimeParser

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

TimeParser handles parsing of time expressions from search queries

func NewTimeParser

func NewTimeParser() *TimeParser

NewTimeParser creates a new time expression parser

func (*TimeParser) GetSupportedFormats

func (tp *TimeParser) GetSupportedFormats() []string

GetSupportedFormats returns a list of supported time expression formats

func (*TimeParser) IsValidTimeExpression

func (tp *TimeParser) IsValidTimeExpression(query string) bool

IsValidTimeExpression checks if a query contains a valid time expression

func (*TimeParser) ParseTimeExpression

func (tp *TimeParser) ParseTimeExpression(query string) *TimeFilter

ParseTimeExpression parses time expressions from a search query

Jump to

Keyboard shortcuts

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