init commit

This commit is contained in:
ysandler
2026-01-27 22:01:30 -06:00
commit ee23a4f39c
22 changed files with 1605 additions and 0 deletions

46
internal/search/search.go Normal file
View File

@@ -0,0 +1,46 @@
package search
import (
"strings"
"github.com/yeho/klp/internal/database"
)
type Result struct {
Entry *database.Entry
}
type Options struct {
MaxResults int
}
func DefaultOptions() Options {
return Options{
MaxResults: 20,
}
}
type Searcher struct {
db *database.Database
}
func NewSearcher(db *database.Database) *Searcher {
return &Searcher{db: db}
}
func (s *Searcher) Search(query string, opts Options) []Result {
queryLower := strings.ToLower(query)
results := []Result{}
entries := s.db.List(0) // Get all entries
for _, entry := range entries {
if strings.Contains(strings.ToLower(entry.Value), queryLower) {
results = append(results, Result{Entry: entry})
if opts.MaxResults > 0 && len(results) >= opts.MaxResults {
break
}
}
}
return results
}