fixed vector search not finding nested tags
This commit is contained in:
@@ -487,7 +487,6 @@ class ProductSearchTest(TestCase):
|
|||||||
# load response data
|
# load response data
|
||||||
payload = response.json()
|
payload = response.json()
|
||||||
# check for object creation
|
# check for object creation
|
||||||
import ipdb; ipdb.set_trace()
|
|
||||||
self.assertEquals(len(payload['products']), len(expected_instances))
|
self.assertEquals(len(payload['products']), len(expected_instances))
|
||||||
# check ids
|
# check ids
|
||||||
for i in range(len(payload['products'])):
|
for i in range(len(payload['products'])):
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ def extract_search_filters(result_set):
|
|||||||
return filter_dict
|
return filter_dict
|
||||||
|
|
||||||
|
|
||||||
def find_related_products(keyword):
|
def find_related_products_v1(keyword):
|
||||||
# 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
|
||||||
@@ -75,23 +75,22 @@ def find_related_products(keyword):
|
|||||||
return products_qs
|
return products_qs
|
||||||
|
|
||||||
|
|
||||||
def alt_rank_find_related_products(keyword):
|
def find_related_products_v2(keyword):
|
||||||
# TODO: figure out why it includes unrelated instances
|
fields=('name', 'description', 'tags__label', 'attributes__label', 'category__name')
|
||||||
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')
|
|
||||||
vector = SearchVector(*fields)
|
vector = SearchVector(*fields)
|
||||||
products_qs = Product.objects.annotate(
|
products_qs = Product.objects.annotate(
|
||||||
search=vector
|
search=vector
|
||||||
).filter(search=keyword)
|
).filter(search=keyword)
|
||||||
return products_qs
|
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
|
||||||
|
|
||||||
|
|||||||
@@ -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, alt_find_related_products, alt_rank_find_related_products
|
from .utils import extract_search_filters, find_related_products_v1, find_related_products_v2, alt_rank_find_related_products
|
||||||
from utils.tag_serializers import TaggitSerializer
|
from utils.tag_serializers import TaggitSerializer
|
||||||
from utils.tag_filters import ProductTagFilter
|
from utils.tag_filters import ProductTagFilter
|
||||||
|
|
||||||
@@ -155,9 +155,9 @@ def product_search(request):
|
|||||||
chunks = query_string.split(' ')
|
chunks = query_string.split(' ')
|
||||||
|
|
||||||
for chunk in chunks:
|
for chunk in chunks:
|
||||||
# products_qs = find_related_products(chunk)
|
products_qs = find_related_products_v1(chunk)
|
||||||
# products_qs = alt_find_related_products(chunk)
|
# products_qs = find_related_products_v2(chunk)
|
||||||
products_qs = alt_rank_find_related_products(chunk)
|
# products_qs = alt_rank_find_related_products(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