Documentation ¶
Index ¶
- Constants
- Variables
- type Algorithm
- type Finder
- func (t *Finder) Exact(input string) bool
- func (t *Finder) Find(input string) (string, float64, bool)
- func (t *Finder) FindCtx(ctx context.Context, input string) (string, float64, bool)
- func (t *Finder) FindTopRankingCtx(ctx context.Context, input string) ([]string, float64, bool)
- func (t *Finder) FindTopRankingPrefixCtx(ctx context.Context, input string, prefixLength uint) (list []string, exact bool, err error)
- func (t *Finder) GetMatchingPrefix(ctx context.Context, prefix string, max uint) ([]string, error)
- func (t *Finder) Refresh(list []string)
- type Option
Constants ¶
const ( WorstScoreValue = -1 * math.MaxFloat32 BestScoreValue = math.MaxFloat32 )
These constants hold the value of the lowest and highest possible scores. Compatible with JSON serialization. It's not ideal to mix presentation with business logic but in this instance it was convenient and similarly effective as math.Inf(-1)
Variables ¶
var (
ErrNoAlgorithmDefined = errors.New("no algorithm defined")
)
Errors
Functions ¶
This section is empty.
Types ¶
type Algorithm ¶
Algorithm the type to comply with to create your own algorithm Note that the return value must be greater than WorstScoreValue and less than BestScoreValue
func NewDamerauLevenshtein ¶ added in v0.1.3
func NewDamerauLevenshtein() Algorithm
NewDamerauLevenshtein returns the DamerauLevenshtein algorithm
func NewJaro ¶ added in v0.1.3
func NewJaro() Algorithm
NewJaro returns the default Jaro algorithm @see https://rosettacode.org/wiki/Jaro_distance#Go
func NewJaroWinkler ¶ added in v0.1.3
NewJaroWinkler returns the JaroWinkler algorithm
func NewJaroWinklerDefaults ¶ added in v0.1.3
func NewJaroWinklerDefaults() Algorithm
NewJaroWinklerDefaults returns the Jaro Winkler algorithm with 0.7 boost threshold and a prefix length of 4
func NewWagnerFischer ¶ added in v0.1.3
NewWagnerFischer returns the NewWagnerFischer algorithm, sensible defaults are: i:1, d:3, s:1
type Finder ¶
type Finder struct { Alg Algorithm LengthTolerance float64 // A number between 0.0-1.0 (percentage) to allow for length miss-match, anything outside this is considered not similar. Set to 0 to disable. // contains filtered or unexported fields }
Finder is the type to find the nearest reference
func (*Finder) Find ¶
Find returns the best alternative a score and if it was an exact match or not. Since algorithms can define their own upper-bound, there is no "best" value.
func (*Finder) FindTopRankingCtx ¶ added in v0.0.3
FindTopRankingCtx returns a list (of at least one element) of references with the same "best" score
func (*Finder) FindTopRankingPrefixCtx ¶ added in v0.1.3
func (t *Finder) FindTopRankingPrefixCtx(ctx context.Context, input string, prefixLength uint) (list []string, exact bool, err error)
FindTopRankingPrefixCtx requires the references to have an exact prefix match on N characters of the input. prefixLength cannot exceed length of input
func (*Finder) GetMatchingPrefix ¶ added in v0.1.3
GetMatchingPrefix returns up to max ref's, that start with the prefix argument
type Option ¶
type Option func(sug *Finder)
Option is the type accepted by finder to set specific options
func WithAlgorithm ¶
WithAlgorithm allows you to set any algorithm
func WithLengthTolerance ¶ added in v0.0.2
WithLengthTolerance defines a percentage of length above we no longer consider a length difference a typo, but instead we consider it as "completely wrong". A value of 0.2 specifies a tolerance of at most ~20% difference in size, with a minimum of 1 character. A value of 0 (the default) disables this feature.
func WithPrefixBuckets ¶ added in v0.1.3
WithPrefixBuckets splits the reference list into buckets by their first letter. Assuming the first letter is correct this can significantly improve the performance by reducing the size of the list to scan through.