Documentation
¶
Index ¶
- func BestPairCombinationJaroWinkler(searchTokens []string, indexedTokens []string) float64
- func BestPairCombinationJaroWinklerWeighted(searchTokens []string, indexedTokens []string, searchWeights []float64, ...) float64
- func BestPairsJaroWinkler(searchTokens []string, indexedTokens []string) float64
- func BestPairsJaroWinklerWeighted(searchTokens []string, indexedTokens []string, searchWeights []float64, ...) float64
- func EncodeSoundex(s string) string
- func GenerateWordCombinations(tokens []string) [][]string
- func JaroWinkler(s1, s2 string) float64
- func JaroWinklerWithFavoritism(indexedTerm, query string, favoritism float64) float64
- func ReloadEnvConfig()
- func ResetEnvConfigForTest()
- func SoundexDistance(s1, s2 string) float64
- func SoundexMatch(s1, s2 string) bool
- func SoundexScore(s1, s2 string) float64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BestPairCombinationJaroWinkler ¶ added in v0.51.0
BestPairCombinationJaroWinkler compares a search query to an indexed term with improved handling of short words and spacing variations
func BestPairCombinationJaroWinklerWeighted ¶ added in v0.57.0
func BestPairCombinationJaroWinklerWeighted(searchTokens []string, indexedTokens []string, searchWeights []float64, indexWeights []float64) float64
BestPairCombinationJaroWinklerWeighted is like BestPairCombinationJaroWinkler but uses TF-IDF weights.
func BestPairsJaroWinkler ¶
BestPairsJaroWinkler compares a search query to an indexed term (name, address, etc) and returns a decimal fraction score.
The algorithm splits each string into tokens, and does a pairwise Jaro-Winkler score of all token combinations (outer product). The best match for each search token is chosen, such that each index token can be matched at most once.
The pairwise scores are combined into an average in a way that corrects for character length, and the fraction of the indexed term that didn't match.
func BestPairsJaroWinklerWeighted ¶ added in v0.57.0
func BestPairsJaroWinklerWeighted(searchTokens []string, indexedTokens []string, searchWeights []float64, indexWeights []float64) float64
BestPairsJaroWinklerWeighted compares a search query to an indexed term using TF-IDF weights. The algorithm is similar to BestPairsJaroWinkler but uses TF-IDF weights instead of character length to weight the importance of each matched term pair.
searchWeights and indexWeights should have the same length as their corresponding token slices. If weights are nil or have different lengths, falls back to unweighted scoring.
func EncodeSoundex ¶ added in v0.62.0
EncodeSoundex returns the standard Soundex code for a string.
Standard rules:
- Retain the first letter of the name.
- Map letters to digits per phonetic group.
- H and W are transparent (ignored) but do NOT reset duplicate tracking.
- Vowels (A,E,I,O,U) and Y separate consonants (reset duplicate tracking).
- Remove consecutive duplicate digits.
- Pad or truncate to letter + 3 digits.
Examples:
- "Smith" → "S530"
- "Lloyd" → "L300" (second L is duplicate of first; O resets; Y like vowel; D=3)
- "Miller" → "M460" (L=4, second L is dup; E resets; R=6)
- "Ashcraft" → "A261" (S=2; H transparent so C=2 is dup of S; R=6; A resets; F=1)
func GenerateWordCombinations ¶ added in v0.51.0
GenerateWordCombinations creates variations of the input words by combining short words with their neighbors, to handle cases like "JSC ARGUMENT" vs "JSCARGUMENT"
func JaroWinkler ¶
jaroWinkler runs the similarly named algorithm over the two input strings and averages their match percentages according to the second string (assumed to be the user's query)
Terms are compared between a few adjacent terms and accumulate the highest near-neighbor match.
For more details see https://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance
func ReloadEnvConfig ¶ added in v0.65.0
func ReloadEnvConfig()
ReloadEnvConfig re-reads environment-controlled scoring flags. Production loads these once at startup; tests may call this after t.Setenv.
func ResetEnvConfigForTest ¶ added in v0.65.0
func ResetEnvConfigForTest()
ResetEnvConfigForTest clears hot-path feature flags to their default (off) state. Intended for test cleanup so parallel/sequential tests do not leak flag values.
func SoundexDistance ¶ added in v0.62.0
SoundexDistance returns 1.0 if Soundex codes match, 0.0 otherwise. The name "Distance" reflects that this is a phonetic similarity measure in the range [0.0, 1.0].
func SoundexMatch ¶ added in v0.62.0
SoundexMatch returns true if two strings encode to the same Soundex code. Two empty strings are considered a match.
func SoundexScore ¶ added in v0.62.0
SoundexScore is an alias for SoundexDistance kept for backwards compatibility.
Types ¶
This section is empty.