added comments
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user