Полнотекстовый поиск с помощью триграмм
пытаюсь сделать триграмму для поиска, но выдаёт ошибку:
ProgrammingError at /
function similarity(character varying, unknown) does not exist
LINE 1: ...opisanie", '')), 'A'), plainto_tsquery('Усат')) + SIMILARITY...
Exception Type: ProgrammingError
Exception Value:
function similarity(character varying, unknown) does not exist
LINE 1: ...opisanie", '')), 'A'), plainto_tsquery('Усат')) + SIMILARITY...
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
Pg_tmg установлен в базе. В setting.py в INSTALLED_APPS добавлено 'django.contrib.postgres.search'.
Код моделей:
from django.db import models
from django.contrib.postgres.search import SearchQuery, SearchRank, SearchVector, TrigramSimilarity
search_vectors = (
SearchVector('stat', weight='A', config='russian') +
SearchVector('polzovatel', weight='A', config='russian') +
SearchVector('email', weight='A', config='russian') +
SearchVector('mesto', weight='A', config='russian') +
SearchVector('avtor', weight='A', config='russian') +
SearchVector('usluga', weight='A', config='russian') +
SearchVector('opisanie', weight='A', config='russian') +
)
class Search_status_Manager(models.Manager):
def search(self, text):
search_query = SearchQuery(text)
search_rank = SearchRank(search_vectors, search_query)
trigram_similarity = TrigramSimilarity('stat', text) \
+ TrigramSimilarity('polzovatel', text) \
+ TrigramSimilarity('email', text) \
+ TrigramSimilarity('mesto', text) \
+ TrigramSimilarity('avtor', text) \
+ TrigramSimilarity('usluga', text) \
+ TrigramSimilarity('opisanie', text)
return self.get_queryset().annotate(
search=search_vectors
).filter(
search=search_query
).annotate(
rank=search_rank + trigram_similarity
).order_by('-rank')
class Status (models.Model):
nomer = models.DecimalField(primary_key=True, max_digits=16, decimal_places=0)
stat = models.CharField(max_length=100, blank=True, null=True)
polzovatel = models.CharField(max_length=400, blank=True, null=True)
email = models.CharField(max_length=100, blank=True, null=True)
mesto = models.CharField(max_length=4000, blank=True, null=True)
avtor = models.CharField(max_length=400, blank=True, null=True)
usluga = models.CharField(max_length=400, blank=True, null=True)
opisanie = models.CharField(max_length=65000, blank=True, null=True)
filters = StatusQuerySet().as_manager()
objects = models.Manager()
objects_manager = Search_status_Manager()
Python 3.6.6
Django 2.2.24
PostgreSQL 12.1