postgres.search.TrigramDistance

class TrigramDistance(expression, string, **extra) [source]

New in Django 1.10.

Accepts a field name or expression, and a string or expression. Returns the trigram distance between the two arguments.

Usage example:

>>> from django.contrib.postgres.search import TrigramDistance
>>> Author.objects.create(name='Katy Stevens')
>>> Author.objects.create(name='Stephen Keats')
>>> test = 'Katie Stephens'
>>> Author.objects.annotate(
...     distance=TrigramDistance('name', test),
... ).filter(distance__lte=0.7).order_by('distance')
[<Author: Katy Stevens>, <Author: Stephen Keats>]
doc_Django
2016-10-09 18:39:23
Comments
Leave a Comment

Please login to continue.