changing the way search workd to accommodate for georestrictions
This commit is contained in:
@@ -567,6 +567,7 @@ class ProductSearchTest(TestCase):
|
||||
self.assertIsNotNone(payload.get('prices'))
|
||||
|
||||
# check for object creation
|
||||
import ipdb; ipdb.set_trace()
|
||||
self.assertEquals(len(payload['products']), len(expected_instances))
|
||||
# check for filters
|
||||
self.assertTrue(len(payload['filters']['tags']) >= 2 )
|
||||
|
||||
@@ -144,7 +144,12 @@ def ranked_product_search(keyword, shipping_cost=None, discount=None, category=N
|
||||
- georesult
|
||||
"""
|
||||
vector = SearchVector('name') + SearchVector('description') + SearchVector('tags__label') + SearchVector('attributes__label') + SearchVector('category__label') + SearchVector('company__company_name')
|
||||
query = SearchQuery(keyword)
|
||||
|
||||
query_string = ''
|
||||
for word in keyword:
|
||||
query_string += f" | '{keyword}' "
|
||||
|
||||
query = SearchQuery(query_string)
|
||||
|
||||
products_qs = Product.objects.annotate(
|
||||
rank=SearchRank(vector, query)
|
||||
|
||||
@@ -201,6 +201,20 @@ def product_search(request):
|
||||
else:
|
||||
# split query string into single words
|
||||
chunks = q.split(' ')
|
||||
# all-in-one search
|
||||
product_set, min_price, max_price, georesult = ranked_product_search(chunks, shipping_cost, discount, category, tags, price_min, price_max, coordinates)
|
||||
# update price values
|
||||
if product_set:
|
||||
if prices['min'] is None or min_price['price__min'] < prices['min']:
|
||||
prices['min'] = min_price['price__min']
|
||||
if prices['max'] is None or max_price['price__max'] > prices['max']:
|
||||
prices['max'] = max_price['price__max']
|
||||
# add to result set
|
||||
result_set.update(product_set)
|
||||
# serialize and list data
|
||||
serializer = SearchResultSerializer(product_set, many=True)
|
||||
result_list = [dict(i) for i in serializer.data]
|
||||
'''
|
||||
for chunk in chunks:
|
||||
product_set, min_price, max_price, georesult = ranked_product_search(chunk, shipping_cost, discount, category, tags, price_min, price_max, coordinates)
|
||||
# update price values
|
||||
@@ -214,6 +228,7 @@ def product_search(request):
|
||||
# serialize and list data
|
||||
serializer = SearchResultSerializer(product_set, many=True)
|
||||
result_list = [dict(i) for i in serializer.data]
|
||||
'''
|
||||
|
||||
# extract filters from result_set
|
||||
filters = extract_search_filters(result_set)
|
||||
|
||||
Reference in New Issue
Block a user