adde find_related_products_v4 to tes trigram indexing
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import logging
|
||||
|
||||
from django.db.models import Q
|
||||
from django.contrib.postgres.search import SearchQuery, SearchRank, SearchVector
|
||||
from django.contrib.postgres.search import SearchQuery, SearchRank, SearchVector, TrigramSimilarity
|
||||
|
||||
from products.models import Product
|
||||
|
||||
@@ -114,3 +114,14 @@ def find_related_products_v3(keyword):
|
||||
).order_by('-rank')
|
||||
return products_qs
|
||||
|
||||
|
||||
def find_related_products_v4(keyword):
|
||||
"""
|
||||
Using trigrams
|
||||
"""
|
||||
fields=('name', 'description', 'tags__label', 'attributes__label', 'category__name')
|
||||
products_qs = Product.objects.annotate(
|
||||
similarity=TrigramSimilarity(fields, keyword)
|
||||
).order_by('-similarity')
|
||||
|
||||
return products_qs
|
||||
|
||||
Reference in New Issue
Block a user