Enrico
Enrico

Reputation: 361

Django TrigramSimilarity search gives no such function: SIMILARITY

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.

Upvotes: 0

Views: 744

Answers (2)

Aldaiar Dushebaev
Aldaiar Dushebaev

Reputation: 26

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

Upvotes: 1

Enrico
Enrico

Reputation: 361

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

Upvotes: 0

Related Questions