Documentation ¶
Overview ¶
Package fuzzy provides fuzzy string matching optimized for filenames and code symbols in the style of Sublime Text, VSCode, IntelliJ IDEA et al.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Match ¶
type Match struct { // The matched string. Str string // The index of the matched string in the supplied slice. Index int // The indexes of matched characters. Useful for highlighting matches. MatchedIndexes []int // Score used to rank matches Score int }
Match represents a matched string.
type Matches ¶ added in v0.0.4
type Matches []Match
Matches is a slice of Match structs
func Find ¶
Find looks up pattern in data and returns matches in descending order of match quality. Match quality is determined by a set of bonus and penalty rules.
The following types of matches apply a bonus:
* The first character in the pattern matches the first character in the match string.
* The matched character is camel cased.
* The matched character follows a separator such as an underscore character.
* The matched character is adjacent to a previous match.
Penalties are applied for every character in the search string that wasn't matched and all leading characters upto the first match.
Results are sorted by best match.
func FindFrom ¶ added in v0.1.0
FindFrom is an alternative implementation of Find using a Source instead of a list of strings.
func FindFromNoSort ¶ added in v0.1.1
FindFromNoSort is an alternative FindFrom implementation that does not sort results in the end.
func FindNoSort ¶ added in v0.1.1
FindNoSort is an alternative Find implementation that does not sort the results in the end.
type Source ¶ added in v0.1.0
type Source interface { // The string to be matched at position i. String(i int) string // The length of the source. Typically is the length of the slice of things that you want to match. Len() int }
Source represents an abstract source of a list of strings. Source must be iterable type such as a slice. The source will be iterated over till Len() with String(i) being called for each element where i is the index of the element. You can find a working example in the README.