added comments

This commit is contained in:
Sam
2021-02-18 13:25:35 +00:00
parent 978a7c9520
commit a06e7eac4d
2 changed files with 23 additions and 3 deletions

View File

@@ -58,6 +58,12 @@ def extract_search_filters(result_set):
def find_related_products_v1(keyword):
"""
Classical approach to the search
Using Q objects
"""
# search in tags
tags = Product.tags.tag_model.objects.filter(name__icontains=keyword)
# search in category
@@ -76,6 +82,11 @@ def find_related_products_v1(keyword):
def find_related_products_v2(keyword):
"""
More advanced search
Using search vectors
"""
fields=('name', 'description', 'tags__label', 'attributes__label', 'category__name')
vector = SearchVector(*fields)
products_qs = Product.objects.annotate(
@@ -84,7 +95,16 @@ def find_related_products_v2(keyword):
return products_qs
def alt_rank_find_related_products(keyword):
def find_related_products_v3(keyword):
"""
Fully loaded product search
SearchVectors for the fields
SearchQuery for the value
SearchRank for relevancy scoring and ranking
PROBLEM: returns unrelated instances
"""
# TODO: figure out why it includes unrelated instances
fields=('name', 'description', 'tags__label', 'attributes__label', 'category__name')
vector = SearchVector(*fields)