1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-13 14:00:25 +00:00
mycorrhiza/shroom/search.go

30 lines
799 B
Go
Raw Normal View History

package shroom
import (
"strings"
"github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/util"
)
2021-08-31 19:28:12 +00:00
// YieldHyphaNamesContainingString picks hyphae with have a string in their title, sorts and iterates over them.
func YieldHyphaNamesContainingString(query string) <-chan string {
2021-12-15 09:19:02 +00:00
query = util.CanonicalName(strings.TrimSpace(query))
out := make(chan string)
2021-08-31 17:12:55 +00:00
sorted := hyphae.PathographicSort(out)
go func() {
for h := range hyphae.YieldExistingHyphae() {
if hyphaNameMatchesString(h.Name, query) {
2021-08-31 17:12:55 +00:00
out <- h.Name
}
}
close(out)
}()
2021-08-31 17:12:55 +00:00
return sorted
}
// This thing gotta be changed one day, when a hero has time to implement a good searching algorithm.
func hyphaNameMatchesString(hyphaName, query string) bool {
return strings.Contains(hyphaName, query)
}