added company_name as a vector in product search
This commit is contained in:
@@ -519,11 +519,13 @@ class ProductSearchTest(TestCase):
|
|||||||
self.model.objects.all().delete()
|
self.model.objects.all().delete()
|
||||||
|
|
||||||
def test_anon_user_can_search(self):
|
def test_anon_user_can_search(self):
|
||||||
|
company = CompanyFactory(company_name='Zapatos Rojos')
|
||||||
expected_instances = [
|
expected_instances = [
|
||||||
self.factory(tags="lunares/rojos", category='zapatos', description="zapatos verdes"),
|
self.factory(tags="lunares/rojos", category='zapatos', description="zapatos verdes"),
|
||||||
self.factory(tags="colores/rojos, tono/brillante"),
|
self.factory(tags="colores/rojos, tono/brillante"),
|
||||||
self.factory(tags="lunares/azules", description="zapatos rojos"),
|
self.factory(tags="lunares/azules", description="zapatos rojos"),
|
||||||
self.factory(tags="lunares/rojos", description="zapatos"),
|
self.factory(tags="lunares/rojos", description="zapatos"),
|
||||||
|
self.factory(tags="lunares/verdes", company=company),
|
||||||
]
|
]
|
||||||
unexpected_instances = [
|
unexpected_instances = [
|
||||||
self.factory(description="chanclas"),
|
self.factory(description="chanclas"),
|
||||||
|
|||||||
@@ -114,12 +114,12 @@ def find_related_products_v6(keyword, shipping_cost=None, discount=None, categor
|
|||||||
allow filtering by:
|
allow filtering by:
|
||||||
- shipping cost
|
- shipping cost
|
||||||
"""
|
"""
|
||||||
vector = SearchVector('name') + SearchVector('description') + SearchVector('tags__label') + SearchVector('attributes__label') + SearchVector('category__name')
|
vector = SearchVector('name') + SearchVector('description') + SearchVector('tags__label') + SearchVector('attributes__label') + SearchVector('category__label') + SearchVector('company__company_name')
|
||||||
query = SearchQuery(keyword)
|
query = SearchQuery(keyword)
|
||||||
|
|
||||||
products_qs = Product.objects.annotate(
|
products_qs = Product.objects.annotate(
|
||||||
rank=SearchRank(vector, query)
|
rank=SearchRank(vector, query)
|
||||||
).filter(rank__gt=0.05) # removed order_by because its lost in casting
|
).filter(rank__gt=0.05)
|
||||||
|
|
||||||
# filter by category
|
# filter by category
|
||||||
if category is not None:
|
if category is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user