Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Comply with existing horrendous type incoherence in search interface
Jakub Draganek36ebb40f86e6
diff --git a/saleor/search/backends/newelastic.py b/saleor/search/backends/newelastic.pyindex dd76850458..0df68bf6cc 100644--- a/saleor/search/backends/newelastic.py+++ b/saleor/search/backends/newelastic.py@@ -2,6 +2,7 @@ from __future__ import unicode_literalsfrom elasticsearch import Elasticsearchfrom django.utils.six.moves.urllib.parse import urlparse+from django.db.models.query import QuerySetfrom elasticsearch_dsl import Searchfrom elasticsearch_dsl.query import MultiMatch@@ -38,12 +39,16 @@ class SearchBackend(object):cls.client = Elasticsearch(hosts=_get_es_hosts(params))def search(self, query, model_or_queryset):- return model_or_queryset.filter(pk__in=search_products(query))+ qs = model_or_queryset+ # TODO: remove this ugly type incoherence of old search api+ if not isinstance(model_or_queryset, QuerySet):+ qs = model_or_queryset.objects.all()+ return qs.filter(pk__in=search_products(query))def search_products(phrase):''' Execute external search for product matching phrase '''- INDEX = 'storefront__product_product' # TODO: parametrize this+ INDEX = 'storefront__product_product'CONTENT = 'product.Product'query = MultiMatch(fields=['name', 'description'], query=phrase)search = (Search(index=INDEX).query(query)