fuzzy

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

README

pg/fuzzy

The fuzzystrmatch extension for sqlb. Needs CREATE EXTENSION fuzzystrmatch.

SQL Helper
dmetaphone, dmetaphone_alt, metaphone, soundex Dmetaphone, DmetaphoneAlt, Metaphone, Soundex
levenshtein, levenshtein_less_equal Levenshtein, LevenshteinLessEqual
difference Difference

Phonetic matching compares codes: sqlb.EqExpr(fuzzy.Dmetaphone(name), fuzzy.Dmetaphone(sqlb.Param("Katherine"))). Edit distance with a threshold uses the less_equal form so the server stops early: sqlb.LessEq(fuzzy.LevenshteinLessEqual(sqlb.Lower(name), sqlb.Param("jonathon"), 2), 2).

Documentation

Overview

Package fuzzy is the fuzzystrmatch extension: phonetic and edit-distance matching. Needs CREATE EXTENSION fuzzystrmatch.

Index

Constants

This section is empty.

Variables

View Source
var Extension = pg.Extension{Name: "fuzzystrmatch"}

Extension is the fuzzystrmatch extension this package's constructs need, for pg.CreateExtension(Extension), so a library installs what it uses without spelling its name.

Functions

func Difference

func Difference(a, b sqlb.Expr[string]) sqlb.Expr[int32]

Difference renders difference(a, b): how many soundex positions agree, 0 to 4.

func Dmetaphone

func Dmetaphone(e sqlb.Expr[string]) sqlb.Expr[string]

Dmetaphone renders dmetaphone(e), the primary double-metaphone code. Two names match phonetically when their codes are equal.

func DmetaphoneAlt

func DmetaphoneAlt(e sqlb.Expr[string]) sqlb.Expr[string]

DmetaphoneAlt renders dmetaphone_alt(e), the alternate code. A name with two accepted pronunciations matches on either code.

func Levenshtein

func Levenshtein(a, b sqlb.Expr[string]) sqlb.Expr[int32]

Levenshtein renders levenshtein(a, b), the full edit distance. Use LevenshteinLessEqual when a threshold is known, because it stops early.

func LevenshteinLessEqual

func LevenshteinLessEqual(a, b sqlb.Expr[string], maxDistance int) sqlb.Expr[int32]

LevenshteinLessEqual stops counting at maxDistance, which is what makes it cheap for a threshold search: the server abandons a pair once it knows the distance exceeds the bound instead of computing the exact value.

func Metaphone

func Metaphone(e sqlb.Expr[string], maxLen int) sqlb.Expr[string]

Metaphone renders metaphone(e, maxLen). maxLen caps the code length and so the strictness of the match.

func Soundex

func Soundex(e sqlb.Expr[string]) sqlb.Expr[string]

Soundex renders soundex(e), the four-character English code. Metaphone and Dmetaphone are more accurate; Soundex is here for existing data.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL