PostgreSQL
1
Вклад в тег
CREATE EXTENSION pg_trgm;
from django.contrib.postgres.search import SearchQuery, SearchRank, SearchVector, TrigramSimilarity
vector = SearchVector('categorysub__name', 'brand__name', 'category__name', 'name', raw=True, fields=('name'))
vector_trgm = TrigramSimilarity('categorysub__name', q, raw=True, fields=('name')) + TrigramSimilarity('brand__name', q, raw=True, fields=('name')) + TrigramSimilarity('category__name', q, raw=True, fields=('name')) + TrigramSimilarity('name', q, raw=True, fields=('name'))
return queryset.annotate(search=vector).order_by('price').filter(search=q) or queryset.annotate(similarity=vector_trgm).filter(similarity__gt=0.2).order_by('price')
TrigramSimilarity
без SearchVector,
то результат поиска будет не всегда правдивым.