Skip to main content
vsql_trgm is a port of PostgreSQL’s pg_trgm. It breaks a string into three-character pieces and scores two strings by how many pieces they share, so a misspelled search term still finds its row. Use it when LIKE is too strict and full-text search is too coarse.

Install

vsql_trgm.veb is already in the server’s lib/veb/ directory if you installed VillageSQL with the install script, the Docker image, or a release tarball. Install it into the server with one statement:
Confirm it is there:
To build it yourself, follow the build instructions in the repository.

What it adds

It adds three families of function. The plain family compares two whole strings. The word family finds the best-matching substring of the second string. The strict word family does the same but aligns on word boundaries. Each family has its own default threshold.

Example

Build a small name table:
Search it for a spelling nobody typed, and rank what comes back:
Peter Brown shares too few trigrams to reach 0.3, so it never appears. To see what is being compared, ask for the trigrams themselves:
The padding spaces are deliberate. They let the start and end of a string count toward the score.
PostgreSQL’s set_limit() has no counterpart here, because a VEF function keeps no session state. Pass the threshold you want to trgm_similar_threshold() instead. A similarity filter also reads every row, so measure it before running one against a large table.

See also