Documentation
¶
Overview ¶
Package trgm is the pg_trgm extension: trigram similarity operators and functions. Needs CREATE EXTENSION pg_trgm. The operators are served by a GIN index with gin_trgm_ops, and the distance operators by GiST with gist_trgm_ops.
Index ¶
- Variables
- func Distance(a, b sqlb.Expr[string]) sqlb.Expr[float32]
- func ShowTrgm(e sqlb.Expr[string]) sqlb.Expr[[]string]
- func Similar(a, b sqlb.Expr[string]) sqlb.Predicate
- func Similarity(a, b sqlb.Expr[string]) sqlb.Expr[float32]
- func StrictWordSimilar(a, b sqlb.Expr[string]) sqlb.Predicate
- func StrictWordSimilarity(a, b sqlb.Expr[string]) sqlb.Expr[float32]
- func WordDistance(a, b sqlb.Expr[string]) sqlb.Expr[float32]
- func WordSimilar(a, b sqlb.Expr[string]) sqlb.Predicate
- func WordSimilarity(a, b sqlb.Expr[string]) sqlb.Expr[float32]
Constants ¶
This section is empty.
Variables ¶
var ( GinOps = pg.NewOpClass[string]("gin_trgm_ops") GistOps = pg.NewOpClass[string]("gist_trgm_ops") )
GinOps and GistOps are the trigram operator classes. GIN is the usual choice for similarity and LIKE search; GiST also serves ordering by distance. A nullable column takes pg.NullableOps(GinOps).
var Extension = pg.Extension{Name: "pg_trgm"}
Extension is the pg_trgm extension this package's constructs need, for pg.CreateExtension(Extension), so a library installs what it uses without spelling its name.
Functions ¶
func ShowTrgm ¶
ShowTrgm renders show_trgm(e), the trigrams themselves. It is a debugging call: it shows why two strings do or do not match.
func Similarity ¶
Similarity renders similarity(a, b), the trigram overlap from 0 to 1. It is the value behind the % operator, for a SELECT item or a threshold of the caller's own.
func StrictWordSimilar ¶
StrictWordSimilar renders a <<% b, the word-boundary form of WordSimilar: the match must cover whole words, not a prefix of one.
func StrictWordSimilarity ¶
StrictWordSimilarity renders strict_word_similarity(a, b), the value behind <<%.
func WordDistance ¶
WordDistance renders a <<-> b, the KNN distance matching WordSimilar.
func WordSimilar ¶
WordSimilar renders a <% b: a matches a word inside b, above pg_trgm.word_similarity_threshold.
Types ¶
This section is empty.