Skip to content

fuzzy

Package fuzzy adds approximate-string-matching SQL scalar functions — edit distances, the Jaro / Jaro-Winkler similarity, and the Soundex phonetic code:

levenshtein(a, b) -- edit distance (insert/delete/substitute)
damerau_levenshtein(a, b) -- + adjacent transposition (OSA variant)
hamming(a, b) -- positions that differ; errors if lengths differ
jaro(a, b) -- Jaro similarity in [0, 1]
jaro_winkler(a, b) -- Jaro with a common-prefix bonus
soundex(s) -- 4-character American Soundex code
caverphone(s) -- 10-character Caverphone 2.0 phonetic code

Distances/similarities are rune-aware (Unicode-correct); Soundex and Caverphone operate on ASCII letters as those algorithms are defined. The cousin to ext/spellfix1 (a vtab-based fuzzy vocabulary): these are stateless scalars over two strings. Ported in spirit from the sqlean fuzzy module.

import (
sqlite "gosqlite.org"
"gosqlite.org/ext/fuzzy"
)
fuzzy.Register(conn) // or blank-import ".../ext/fuzzy/auto" for pool-wide
db.QueryRow(`SELECT levenshtein('kitten', 'sitting')`) // 3

Full API: pkg.go.dev/gosqlite.org/ext/fuzzy