summaryrefslogtreecommitdiffstats
path: root/pkg/utils/fuzzy_search.go
blob: 4199d6c8b431f11c65cb196a3535b4fccd9a7e5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package utils

import (
	"sort"

	"github.com/sahilm/fuzzy"
)

func FuzzySearch(needle string, haystack []string) []string {
	if needle == "" {
		return []string{}
	}

	matches := fuzzy.Find(needle, haystack)
	sort.Sort(matches)

	result := make([]string, len(matches))
	for i, match := range matches {
		result[i] = match.Str
	}

	return result
}