added comments
This commit is contained in:
@@ -58,6 +58,12 @@ def extract_search_filters(result_set):
|
|||||||
|
|
||||||
|
|
||||||
def find_related_products_v1(keyword):
|
def find_related_products_v1(keyword):
|
||||||
|
"""
|
||||||
|
Classical approach to the search
|
||||||
|
|
||||||
|
Using Q objects
|
||||||
|
|
||||||
|
"""
|
||||||
# search in tags
|
# search in tags
|
||||||
tags = Product.tags.tag_model.objects.filter(name__icontains=keyword)
|
tags = Product.tags.tag_model.objects.filter(name__icontains=keyword)
|
||||||
# search in category
|
# search in category
|
||||||
@@ -76,6 +82,11 @@ def find_related_products_v1(keyword):
|
|||||||
|
|
||||||
|
|
||||||
def find_related_products_v2(keyword):
|
def find_related_products_v2(keyword):
|
||||||
|
"""
|
||||||
|
More advanced search
|
||||||
|
|
||||||
|
Using search vectors
|
||||||
|
"""
|
||||||
fields=('name', 'description', 'tags__label', 'attributes__label', 'category__name')
|
fields=('name', 'description', 'tags__label', 'attributes__label', 'category__name')
|
||||||
vector = SearchVector(*fields)
|
vector = SearchVector(*fields)
|
||||||
products_qs = Product.objects.annotate(
|
products_qs = Product.objects.annotate(
|
||||||
@@ -84,7 +95,16 @@ def find_related_products_v2(keyword):
|
|||||||
return products_qs
|
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
|
# TODO: figure out why it includes unrelated instances
|
||||||
fields=('name', 'description', 'tags__label', 'attributes__label', 'category__name')
|
fields=('name', 'description', 'tags__label', 'attributes__label', 'category__name')
|
||||||
vector = SearchVector(*fields)
|
vector = SearchVector(*fields)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ from companies.models import Company
|
|||||||
from history.models import HistorySync
|
from history.models import HistorySync
|
||||||
|
|
||||||
from back_latienda.permissions import IsCreator
|
from back_latienda.permissions import IsCreator
|
||||||
from .utils import extract_search_filters, find_related_products_v1, find_related_products_v2, alt_rank_find_related_products
|
from .utils import extract_search_filters, find_related_products_v1, find_related_products_v2, find_related_products_v3
|
||||||
from utils.tag_serializers import TaggitSerializer
|
from utils.tag_serializers import TaggitSerializer
|
||||||
from utils.tag_filters import ProductTagFilter
|
from utils.tag_filters import ProductTagFilter
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ def product_search(request):
|
|||||||
for chunk in chunks:
|
for chunk in chunks:
|
||||||
products_qs = find_related_products_v1(chunk)
|
products_qs = find_related_products_v1(chunk)
|
||||||
# products_qs = find_related_products_v2(chunk)
|
# products_qs = find_related_products_v2(chunk)
|
||||||
# products_qs = alt_rank_find_related_products(chunk)
|
# products_qs = find_related_products_v3(chunk)
|
||||||
for instance in products_qs:
|
for instance in products_qs:
|
||||||
result_set.add(instance)
|
result_set.add(instance)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user