Merge branch 'development' into diego
This commit is contained in:
@@ -85,35 +85,45 @@ def extract_search_filters(result_set):
|
||||
return filter_dict
|
||||
|
||||
|
||||
def find_related_products_v7(description, tags, attributes, category):
|
||||
products_qs = Product.objects.filter(
|
||||
description=description,
|
||||
tags__in=tags,
|
||||
attributes__in=attributes,
|
||||
category=category
|
||||
)[:6]
|
||||
return products_qs
|
||||
|
||||
|
||||
def find_related_products_v3(keyword):
|
||||
def get_related_products(product):
|
||||
"""Make different db searches until you get 10 instances to return
|
||||
"""
|
||||
Ranked product search
|
||||
total_results = []
|
||||
|
||||
SearchVectors for the fields
|
||||
SearchQuery for the value
|
||||
SearchRank for relevancy scoring and ranking
|
||||
"""
|
||||
vector = SearchVector('name') + SearchVector('description') + SearchVector('tags__label') + SearchVector('attributes__label') + SearchVector('category__name')
|
||||
query = SearchQuery(keyword)
|
||||
# search by category
|
||||
category_qs = Product.objects.filter(category=product.category)[:10]
|
||||
# add to results
|
||||
for item in category_qs:
|
||||
total_results.append(item)
|
||||
|
||||
products_qs = Product.objects.annotate(
|
||||
rank=SearchRank(vector, query)
|
||||
).filter(rank__gt=0.05) # removed order_by because its lost in casting
|
||||
# check size
|
||||
if len(total_results) < 10:
|
||||
# search by tags
|
||||
tags_qs = Product.objects.filter(tags__in=product.tags.all())[:10]
|
||||
# add to results
|
||||
for item in tags_qs:
|
||||
total_results.append(item)
|
||||
|
||||
return set(products_qs)
|
||||
# check size
|
||||
if len(total_results) < 10:
|
||||
# search by coop
|
||||
coop_qs = Product.objects.filter(company=product.company)[:10]
|
||||
# add to results
|
||||
for item in coop_qs:
|
||||
total_results.append(item)
|
||||
|
||||
# check size
|
||||
if len(total_results) < 10:
|
||||
# search by latest
|
||||
latest_qs = Product.objects.order_by('-created')[:10]
|
||||
# add to results
|
||||
for item in coop_qs:
|
||||
total_results.append(item)
|
||||
|
||||
return total_results[:10]
|
||||
|
||||
|
||||
def find_related_products_v6(keyword, shipping_cost=None, discount=None, category=None, tags=None, price_min=None,price_max=None):
|
||||
def ranked_product_search(keyword, shipping_cost=None, discount=None, category=None, tags=None, price_min=None,price_max=None):
|
||||
"""
|
||||
Ranked product search
|
||||
|
||||
|
||||
Reference in New Issue
Block a user