2021-07-12 13:25:57 +00:00
|
|
|
package shroom
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
|
|
|
"github.com/bouncepaw/mycorrhiza/util"
|
|
|
|
)
|
|
|
|
|
2022-04-02 08:00:10 +00:00
|
|
|
// YieldHyphaNamesContainingString picks hyphae with have a string in their title, sorts and iterates over them in alphabetical order.
|
2021-07-12 13:25:57 +00:00
|
|
|
func YieldHyphaNamesContainingString(query string) <-chan string {
|
2021-12-15 09:19:02 +00:00
|
|
|
query = util.CanonicalName(strings.TrimSpace(query))
|
2021-07-12 13:25:57 +00:00
|
|
|
out := make(chan string)
|
2021-08-31 17:12:55 +00:00
|
|
|
sorted := hyphae.PathographicSort(out)
|
2021-07-12 13:25:57 +00:00
|
|
|
go func() {
|
|
|
|
for h := range hyphae.YieldExistingHyphae() {
|
2022-02-03 21:47:36 +00:00
|
|
|
if hyphaNameMatchesString(h.CanonicalName(), query) {
|
|
|
|
out <- h.CanonicalName()
|
2021-07-12 13:25:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
close(out)
|
|
|
|
}()
|
2021-08-31 17:12:55 +00:00
|
|
|
return sorted
|
2021-07-12 13:25:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|