postgres.search.TrigramSimilarity

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

New in Django 1.10.

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

Usage example:

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

Please login to continue.