changed product search param from query_string to q
This commit is contained in:
@@ -214,7 +214,7 @@ Endpoint: `/api/v1/product_search/`
|
|||||||
|
|
||||||
Query parameters:
|
Query parameters:
|
||||||
|
|
||||||
- `query_string`: text from the search input box
|
- `q`: text from the search input box
|
||||||
|
|
||||||
|
|
||||||
Response format:
|
Response format:
|
||||||
|
|||||||
@@ -528,9 +528,9 @@ class ProductSearchTest(TestCase):
|
|||||||
self.factory(tags="azules"),
|
self.factory(tags="azules"),
|
||||||
]
|
]
|
||||||
|
|
||||||
query_string = quote("zapatos rojos")
|
q = quote("zapatos rojos")
|
||||||
|
|
||||||
url = f"{self.endpoint}?query_string={query_string}"
|
url = f"{self.endpoint}?q={q}"
|
||||||
# send in request
|
# send in request
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
|
|
||||||
@@ -562,10 +562,10 @@ class ProductSearchTest(TestCase):
|
|||||||
self.factory(tags="azules"),
|
self.factory(tags="azules"),
|
||||||
]
|
]
|
||||||
|
|
||||||
query_string = quote("zapatos rojos")
|
q = quote("zapatos rojos")
|
||||||
limit = 2
|
limit = 2
|
||||||
|
|
||||||
url = f"{self.endpoint}?query_string={query_string}&limit=2"
|
url = f"{self.endpoint}?q={q}&limit=2"
|
||||||
# send in request
|
# send in request
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
|
|
||||||
@@ -589,9 +589,9 @@ class ProductSearchTest(TestCase):
|
|||||||
self.factory(tags="lunares/rojos", description="zapatos", shipping_cost=0.00),
|
self.factory(tags="lunares/rojos", description="zapatos", shipping_cost=0.00),
|
||||||
]
|
]
|
||||||
|
|
||||||
query_string = quote("zapatos rojos")
|
q = quote("zapatos rojos")
|
||||||
# shipping_cost=true
|
# shipping_cost=true
|
||||||
url = f"{self.endpoint}?query_string={query_string}&shipping_cost=true"
|
url = f"{self.endpoint}?q={q}&shipping_cost=true"
|
||||||
# send in request
|
# send in request
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
# check response
|
# check response
|
||||||
@@ -610,10 +610,10 @@ class ProductSearchTest(TestCase):
|
|||||||
self.factory(tags="azules", shipping_cost=10.00),
|
self.factory(tags="azules", shipping_cost=10.00),
|
||||||
]
|
]
|
||||||
|
|
||||||
query_string = quote("zapatos rojos")
|
q = quote("zapatos rojos")
|
||||||
|
|
||||||
# shipping_cost=false
|
# shipping_cost=false
|
||||||
url = f"{self.endpoint}?query_string={query_string}&shipping_cost=false"
|
url = f"{self.endpoint}?q={q}&shipping_cost=false"
|
||||||
# send in request
|
# send in request
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
# check response
|
# check response
|
||||||
@@ -633,9 +633,9 @@ class ProductSearchTest(TestCase):
|
|||||||
self.factory(tags="lunares/rojos", category='zapatos', description="zapatos verdes", discount=None),
|
self.factory(tags="lunares/rojos", category='zapatos', description="zapatos verdes", discount=None),
|
||||||
]
|
]
|
||||||
|
|
||||||
query_string = quote("zapatos rojos")
|
q = quote("zapatos rojos")
|
||||||
# discount=true
|
# discount=true
|
||||||
url = f"{self.endpoint}?query_string={query_string}&discount=true"
|
url = f"{self.endpoint}?q={q}&discount=true"
|
||||||
# send in request
|
# send in request
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
# check response
|
# check response
|
||||||
@@ -655,9 +655,9 @@ class ProductSearchTest(TestCase):
|
|||||||
self.factory(tags="azules", discount=9.00),
|
self.factory(tags="azules", discount=9.00),
|
||||||
]
|
]
|
||||||
|
|
||||||
query_string = quote("zapatos rojos")
|
q = quote("zapatos rojos")
|
||||||
# discount=true
|
# discount=true
|
||||||
url = f"{self.endpoint}?query_string={query_string}&discount=false"
|
url = f"{self.endpoint}?q={q}&discount=false"
|
||||||
# send in request
|
# send in request
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
# check response
|
# check response
|
||||||
@@ -677,9 +677,8 @@ class ProductSearchTest(TestCase):
|
|||||||
self.factory(tags="azules"),
|
self.factory(tags="azules"),
|
||||||
]
|
]
|
||||||
|
|
||||||
query_string = quote("zapatos rojos")
|
|
||||||
# discount=true
|
# discount=true
|
||||||
url = f"{self.endpoint}?query_string="
|
url = f"{self.endpoint}?q="
|
||||||
# send in request
|
# send in request
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
# check response
|
# check response
|
||||||
@@ -699,9 +698,9 @@ class ProductSearchTest(TestCase):
|
|||||||
self.factory(tags="zapatos/azules", category="deporte", description='rojos', discount=12.00),
|
self.factory(tags="zapatos/azules", category="deporte", description='rojos', discount=12.00),
|
||||||
]
|
]
|
||||||
|
|
||||||
query_string = quote("zapatos rojos")
|
q = quote("zapatos rojos")
|
||||||
# discount=true
|
# discount=true
|
||||||
url = f"{self.endpoint}?query_string={query_string}&category=ropa"
|
url = f"{self.endpoint}?q={q}&category=ropa"
|
||||||
# send in request
|
# send in request
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
# check response
|
# check response
|
||||||
@@ -721,9 +720,9 @@ class ProductSearchTest(TestCase):
|
|||||||
self.factory(tags="zapatos/azules", category="deporte", description='rojos', discount=12.00),
|
self.factory(tags="zapatos/azules", category="deporte", description='rojos', discount=12.00),
|
||||||
]
|
]
|
||||||
|
|
||||||
query_string = quote("zapatos rojos")
|
q = quote("zapatos rojos")
|
||||||
# discount=true
|
# discount=true
|
||||||
url = f"{self.endpoint}?query_string={query_string}&tags=deporte"
|
url = f"{self.endpoint}?q={q}&tags=deporte"
|
||||||
# send in request
|
# send in request
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
# check response
|
# check response
|
||||||
@@ -743,8 +742,8 @@ class ProductSearchTest(TestCase):
|
|||||||
self.factory(tags="lunares/rojos", category='zapatos', description="zapatos verdes", price=None),
|
self.factory(tags="lunares/rojos", category='zapatos', description="zapatos verdes", price=None),
|
||||||
]
|
]
|
||||||
price_min = 5.00
|
price_min = 5.00
|
||||||
query_string = quote("zapatos rojos")
|
q = quote("zapatos rojos")
|
||||||
url = f"{self.endpoint}?query_string={query_string}&price_min={price_min}"
|
url = f"{self.endpoint}?q={q}&price_min={price_min}"
|
||||||
# send in request
|
# send in request
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
|
|
||||||
@@ -767,8 +766,8 @@ class ProductSearchTest(TestCase):
|
|||||||
self.factory(tags="lunares/rojos", category='zapatos', description="zapatos verdes", price=100.00),
|
self.factory(tags="lunares/rojos", category='zapatos', description="zapatos verdes", price=100.00),
|
||||||
]
|
]
|
||||||
price_max = 50.00
|
price_max = 50.00
|
||||||
query_string = quote("zapatos rojos")
|
q = quote("zapatos rojos")
|
||||||
url = f"{self.endpoint}?query_string={query_string}&price_max={price_max}"
|
url = f"{self.endpoint}?q={q}&price_max={price_max}"
|
||||||
# send in request
|
# send in request
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
|
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ def product_search(request):
|
|||||||
Takes a string of data, return relevant products
|
Takes a string of data, return relevant products
|
||||||
|
|
||||||
Params:
|
Params:
|
||||||
- query_string: used for search [MANDATORY]
|
- q: used for search [MANDATORY]
|
||||||
- limit: max number of returned instances [OPTIONAL]
|
- limit: max number of returned instances [OPTIONAL]
|
||||||
- offset: where to start counting results [OPTIONAL]
|
- offset: where to start counting results [OPTIONAL]
|
||||||
- shipping_cost: true/false
|
- shipping_cost: true/false
|
||||||
@@ -159,7 +159,7 @@ def product_search(request):
|
|||||||
- tags: string
|
- tags: string
|
||||||
"""
|
"""
|
||||||
# capture query params
|
# capture query params
|
||||||
query_string = request.GET.get('query_string', None)
|
q = request.GET.get('q', None)
|
||||||
limit = request.GET.get('limit', None)
|
limit = request.GET.get('limit', None)
|
||||||
offset = request.GET.get('offset', None)
|
offset = request.GET.get('offset', None)
|
||||||
shipping_cost = request.GET.get('shipping_cost', None)
|
shipping_cost = request.GET.get('shipping_cost', None)
|
||||||
@@ -183,9 +183,9 @@ def product_search(request):
|
|||||||
price_min = request.GET.get('price_min', None)
|
price_min = request.GET.get('price_min', None)
|
||||||
price_max = request.GET.get('price_max', None)
|
price_max = request.GET.get('price_max', None)
|
||||||
|
|
||||||
if query_string is None:
|
if q is None:
|
||||||
return Response({"errors": {"details": "No query string to parse"}})
|
return Response({"errors": {"details": "No query string to parse"}})
|
||||||
elif query_string is '':
|
elif q is '':
|
||||||
# return everything
|
# return everything
|
||||||
serializer = ProductSerializer(Product.objects.all(), many=True)
|
serializer = ProductSerializer(Product.objects.all(), many=True)
|
||||||
products = serializer.data
|
products = serializer.data
|
||||||
@@ -196,7 +196,7 @@ def product_search(request):
|
|||||||
result_set = set()
|
result_set = set()
|
||||||
|
|
||||||
# split query string into single words
|
# split query string into single words
|
||||||
chunks = query_string.split(' ')
|
chunks = q.split(' ')
|
||||||
for chunk in chunks:
|
for chunk in chunks:
|
||||||
product_set = find_related_products_v6(chunk, shipping_cost, discount, category, tags, price_min, price_max)
|
product_set = find_related_products_v6(chunk, shipping_cost, discount, category, tags, price_min, price_max)
|
||||||
# add to result set
|
# add to result set
|
||||||
|
|||||||
Reference in New Issue
Block a user