very basic and unoptimized search functionality is working
This commit is contained in:
@@ -356,6 +356,9 @@ class ProductSearchTest(TestCase):
|
||||
self.user.save()
|
||||
|
||||
def test_anon_user_can_search(self):
|
||||
self.factory(description="zapatos")
|
||||
self.factory(tags="rojos")
|
||||
|
||||
query_string = quote("zapatos rojos")
|
||||
|
||||
url = f"{self.endpoint}?query_string={query_string}"
|
||||
@@ -366,7 +369,7 @@ class ProductSearchTest(TestCase):
|
||||
# check re sponse
|
||||
self.assertEqual(response.status_code, 200)
|
||||
# check for object creation
|
||||
self.assertEquals(5, self.model.objects.count())
|
||||
self.assertEquals(2, self.model.objects.count())
|
||||
|
||||
|
||||
class MyProductsViewTest(APITestCase):
|
||||
|
||||
@@ -121,30 +121,30 @@ def product_search(request):
|
||||
chunks = query_string.split(' ')
|
||||
|
||||
result_set = set()
|
||||
import ipdb; ipdb.set_trace()
|
||||
# import ipdb; ipdb.set_trace()
|
||||
for chunk in chunks:
|
||||
import ipdb; ipdb.set_trace()
|
||||
# search in name
|
||||
products = Product.objects.filter(name__in=chunk)
|
||||
products = Product.objects.filter(name=chunk)
|
||||
for item in products:
|
||||
result_set.add(item)
|
||||
# search in description
|
||||
products = Product.objects.filter(description__in=chunk)
|
||||
products = Product.objects.filter(description=chunk)
|
||||
for item in products:
|
||||
result_set.add(item)
|
||||
# search in tags
|
||||
products = Product.objects.filter(tags__in=chunk)
|
||||
products = Product.objects.filter(tags=chunk)
|
||||
for item in products:
|
||||
result_set.add(item)
|
||||
# search in category
|
||||
products = Product.objects.filter(category__in=chunk)
|
||||
products = Product.objects.filter(category=chunk)
|
||||
for item in products:
|
||||
result_set.add(item)
|
||||
# search in attributes
|
||||
products = Product.objects.filter(attributes__in=chunk)
|
||||
products = Product.objects.filter(attributes=chunk)
|
||||
for item in products:
|
||||
result_set.add(item)
|
||||
|
||||
return Response(data=result_set)
|
||||
data = serializers.serialize('json', result_set)
|
||||
return Response(data=data)
|
||||
except Exception as e:
|
||||
return Response({"errors": {"details": str(type(e))}})
|
||||
|
||||
Reference in New Issue
Block a user