product search with ranking is working
This commit is contained in:
@@ -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')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user