Django TrigramSimilarity search gives no such function: SIMILARITY

Question:

I am trying to do a TrigramSimilarity search in my Django project.
As written in the django documentation i have done the following import: from django.contrib.postgres.search import TrigramSimilarity;
I have also added 'django.contrib.postgres' inside the INSTALLED_APPS of the settings.py file.

The error does not come instantly: i receive this error Django TrigramSimilarity search gives no such function: SIMILARITY once i do something with the queryset.
For example if i want to do a simple operation such as a print(), the error comes. The code below is what i have done

articles = Article.objects.annotate(
    similarity=TrigramSimilarity('name', search_str),
).filter(similarity__gt=0.3).order_by('-similarity')
print(articles) #that line causes the error (no such function: SIMILARITY)

I have literally searched for everything, but it seems that no one had this error before.
I have exactly did what the documentation says -> here

Maybe there is another way to do a TrigramSimilarity, but as i said before i read the documentation.

Asked By: Enrico

||

Answers:

I solved creating manually a function that reproduces Trigraman Similarity Search.

Answered By: Enrico

You should add pg_trgm extension to your postgres.
And after that postgres will understand TrigramSimilarity.

Answered By: Aldaiar Dushebaev
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.