pgtrgm
PostgreSQL pg_trgm extension support for Diesel.
A fork of triforce_rs, this crate
provides bindings for PostgreSQL's pg_trgm extension, enabling trigram-based
text similarity matching and fuzzy search.
Features
- Full query builder integration with operators and functions
- Trigram similarity operators (
%,<%,%>,<<%,%>>) - Distance operators (
<->,<<->,<->>,<<<->,<->>>)
Installation
Add this to your Cargo.toml:
[]
= { = "0.4", = ["diesel"] }
PostgreSQL Setup
Ensure the pg_trgm extension is enabled in your database:
CREATE EXTENSION IF NOT EXISTS pg_trgm;
For optimal performance, create a GIN index on columns you'll search:
(name gin_trgm_ops);
Usage
use *;
use *;
// Find similar names
let results = table
.filter
.order_by
.?;
// Get similarity score
let results = table
.select
.filter
.?;
// Word similarity for matching within longer text
let results = table
.filter
.?;
Related Crates
- diesel_full_text_search — PostgreSQL Full Text Search support for Diesel
- pgvector-rust — PostgreSQL Vector Similarity Search support for Diesel
Contributing
Contributions are welcome! Please read our Contributing Guide for details on how to submit pull requests, report issues, and contribute to the project.
License
This project is licensed under the MIT License - see the LICENSE.txt file for details.