product search with ranking is working

This commit is contained in:
Sam
2021-02-19 11:20:03 +00:00
parent 8abcda74f8
commit e31c64eea8
3 changed files with 24 additions and 19 deletions

View File

@@ -114,25 +114,21 @@ def find_related_products_v3(keyword):
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('name') + SearchVector('description') + SearchVector('tags__label') + SearchVector('attributes__label') + SearchVector('category__name')
query = SearchQuery(keyword)
products_qs = Product.objects.annotate(
rank=SearchRank(vector, query)
).filter(rank__gt=0.05).order_by('-rank')
).filter(rank__gt=0.05) # removed order_by because its lost in casting
return set(products_qs)
def find_related_products_v4(keyword):
"""
Using trigrams
Similarity-ranked search using trigrams
Not working
"""
# fields=('name', 'description', 'tags__label', 'attributes__label', 'category__name')