new and improved Q-based search implementation
This commit is contained in:
@@ -81,11 +81,23 @@ def find_related_products_v1(keyword):
|
||||
return products_qs
|
||||
|
||||
|
||||
def find_related_products_v5(keyword):
|
||||
"""
|
||||
Single query solution, using Q objects
|
||||
"""
|
||||
products_qs = Product.objects.filter(
|
||||
Q(name__icontains=keyword)|
|
||||
Q(description__icontains=keyword)|
|
||||
Q(tags__label__icontains=keyword)|
|
||||
Q(category__name__icontains=keyword)|
|
||||
Q(attributes__label__icontains=keyword)
|
||||
)
|
||||
return products_qs
|
||||
|
||||
|
||||
def find_related_products_v2(keyword):
|
||||
"""
|
||||
More advanced search
|
||||
|
||||
Using search vectors
|
||||
More advanced: using search vectors
|
||||
"""
|
||||
fields=('name', 'description', 'tags__label', 'attributes__label', 'category__name')
|
||||
vector = SearchVector(*fields)
|
||||
|
||||
Reference in New Issue
Block a user