fixes addtestdata, working on vectorized database search
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
|
||||
from django.db.models import Q
|
||||
from django.contrib.postgres.search import SearchQuery, SearchRank, SearchVector
|
||||
|
||||
from products.models import Product
|
||||
|
||||
@@ -72,3 +73,15 @@ def find_related_products(keyword):
|
||||
Q(attributes__in=attributes)
|
||||
)
|
||||
return products_qs
|
||||
|
||||
|
||||
def search_by_phrase(phrase):
|
||||
SearchQuery(phrase, search_type='phrase')
|
||||
pass
|
||||
|
||||
|
||||
def alt_find_related_products(keyword, fields=('tags', 'attributes', 'category')):
|
||||
vector = SearchVector(*fields)
|
||||
products_qs = Product.objects.annotate(search=vector).filter(search=keyword)
|
||||
return products_qs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user