Last active
August 1, 2020 13:28
-
-
Save Tethik/bbd4eaec2b67f9e8eb3696fe0689330a to your computer and use it in GitHub Desktop.
not so efficient file searching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Searcher struct { | |
data []*DesktopApp | |
} | |
func SearcherNew() *Searcher { | |
// TODO: might be worth caching / indexing here somehow. | |
var all []*DesktopApp | |
paths := applicationDirs() | |
log.Infof("Application dirs:\n %s", paths) | |
seen := map[string]bool{} | |
for _, p := range paths { | |
apps := enumerateDirForApps(p) | |
for _, a := range apps { | |
// Lazy way to filter out duplicates | |
if _, ok := seen[a.Name]; !ok { | |
all = append(all, a) | |
seen[a.Name] = true | |
} | |
} | |
} | |
return &Searcher{all} | |
} | |
func (s *Searcher) SearchApps(text string) (result []*DesktopApp) { | |
for _, a := range s.data { | |
// Lazy solution for now. | |
if strings.Contains(strings.ToLower(a.Name), strings.ToLower(text)) { | |
result = append(result, a) | |
} | |
} | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment