fixes addtestdata, working on vectorized database search
This commit is contained in:
@@ -477,6 +477,9 @@ class ProductSearchTest(TestCase):
|
||||
url = f"{self.endpoint}?query_string={query_string}"
|
||||
# send in request
|
||||
response = self.client.get(url)
|
||||
|
||||
import ipdb; ipdb.set_trace()
|
||||
|
||||
payload = response.json()
|
||||
# check response
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ from companies.models import Company
|
||||
from history.models import HistorySync
|
||||
|
||||
from back_latienda.permissions import IsCreator
|
||||
from .utils import extract_search_filters, find_related_products
|
||||
from .utils import extract_search_filters, find_related_products, alt_find_related_products
|
||||
from utils.tag_serializers import TaggitSerializer
|
||||
from utils.tag_filters import ProductTagFilter
|
||||
|
||||
@@ -155,7 +155,8 @@ def product_search(request):
|
||||
chunks = query_string.split(' ')
|
||||
|
||||
for chunk in chunks:
|
||||
products_qs = find_related_products(chunk)
|
||||
# products_qs = find_related_products(chunk)
|
||||
products_qs = alt_find_related_products(chunk)
|
||||
for instance in products_qs:
|
||||
result_set.add(instance)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user