feat: filter and search by tag

This commit is contained in:
2026-02-03 09:53:08 +01:00
parent cb11e34798
commit 229223f77a
9 changed files with 147 additions and 14 deletions

View File

@ -67,13 +67,25 @@ func (ns *NoteStorage) Search(query string) []*note.Note {
for _, note := range ns.Index {
lowContent := strings.ToLower(string(note.Content))
lowQuery := strings.ToLower(query)
if strings.Contains(lowContent, lowQuery) {
if strings.Contains(lowContent, lowQuery) || tagsContain(note.Tags, lowQuery) {
results = append(results, note)
}
}
return results
}
func tagsContain(tags []string, query string) bool {
if query == "" {
return false
}
for _, tag := range tags {
if strings.Contains(strings.ToLower(tag), query) {
return true
}
}
return false
}
func (ns *NoteStorage) AddTag(noteID, tag string) error {
n, ok := ns.Index[noteID]
if !ok {