fixed vector search not finding nested tags

This commit is contained in:
Sam
2021-02-18 13:22:08 +00:00
parent 47633c889d
commit 978a7c9520
3 changed files with 18 additions and 20 deletions

View File

@@ -57,7 +57,7 @@ def extract_search_filters(result_set):
return filter_dict
def find_related_products(keyword):
def find_related_products_v1(keyword):
# search in tags
tags = Product.tags.tag_model.objects.filter(name__icontains=keyword)
# search in category
@@ -75,23 +75,22 @@ def find_related_products(keyword):
return products_qs
def alt_rank_find_related_products(keyword):
# TODO: figure out why it includes unrelated instances
fields=('name', 'description', 'tags__name', 'attributes__name', 'category__name')
vector = SearchVector(*fields)
query = SearchQuery(keyword)
products_qs = Product.objects.annotate(
rank=SearchRank(vector, query)
).order_by('-rank')
import ipdb; ipdb.set_trace()
return products_qs
def alt_find_related_products(keyword):
fields=('name', 'description', 'tags__name', 'attributes__name', 'category__name')
def find_related_products_v2(keyword):
fields=('name', 'description', 'tags__label', 'attributes__label', 'category__name')
vector = SearchVector(*fields)
products_qs = Product.objects.annotate(
search=vector
).filter(search=keyword)
return products_qs
def alt_rank_find_related_products(keyword):
# TODO: figure out why it includes unrelated instances
fields=('name', 'description', 'tags__label', 'attributes__label', 'category__name')
vector = SearchVector(*fields)
query = SearchQuery(keyword)
products_qs = Product.objects.annotate(
rank=SearchRank(vector, query)
).order_by('-rank')
return products_qs