Skip to main content

Django application with some addons regarding PostgreSQL trigram text comparison

Project description


Django pgtrgm is a Django application with some addons regarding PostgreSQL trigram
(or trigraph) text comparison

A trigram is a group of three consecutive characters taken from a string. We can
measure the similarity of two strings by counting the number of trigrams they share.
This simple idea turns out to be very effective for measuring the similarity of words
in many natural languages.

For example, the set of trigrams in the string "cat" is " c", " ca", "cat", and "at ".

With this extension, we could use this feature inside Django ORM with a simple
QuerySet filter keyword

It is distributed under the terms of the [GNU Lesser General Public

PostgreSQL syntax

`text % text` -> boolean Returns true if its arguments have a similarity that is greater
than the current similarity threshold set by set_limit.

[How to install and use pg_trgm extension in PostgreSQL 9.2](


Django 1.5 (or higher). It's possible that works with other versions lower 1.5


In your




Adds a new query set filter keyword to allow text searching.


To ensure results ordered by similarity, try this:

extra(select={'distance': "similarity(name, 'whatever')"}).


You can get the last version of djorm-ext-pgtrgm by doing a clone
of its repository:

git clone git://

0.0.1 (2013-10-23)

* First version to djorm-ext-pgtrgm

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djorm-ext-pgtrgm-0.1.tar.gz (16.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page