Matches returns the closest matches to the needle from the haystack. The maxDistance parameter is the maximum Matches distance to consider. If no matches are found, an empty slice is returned.
(needle string, maxDistance int, haystack ...string)
| 9 | // The maxDistance parameter is the maximum Matches distance to consider. |
| 10 | // If no matches are found, an empty slice is returned. |
| 11 | func Matches(needle string, maxDistance int, haystack ...string) (matches []string) { |
| 12 | for _, hay := range haystack { |
| 13 | if d, err := Distance(needle, hay, maxDistance); err == nil && d <= maxDistance { |
| 14 | matches = append(matches, hay) |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | return matches |
| 19 | } |
| 20 | |
| 21 | var ErrMaxDist = xerrors.New("levenshtein: maxDist exceeded") |
| 22 |