Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Filter published items in search query
Jakub Draganekf00f141d2f97
diff --git a/saleor/search/backends/newelastic.py b/saleor/search/backends/newelastic.pyindex 6a3c78f9e2..eddad847ee 100644--- a/saleor/search/backends/newelastic.py+++ b/saleor/search/backends/newelastic.py@@ -15,23 +15,23 @@ def search_products(phrase):CONTENT = 'product.Product'query = MultiMatch(fields=['name', 'description'], query=phrase)search = (Search(index=INDEX).query(query)+ .filter('term', is_published_filter=True)+ .filter('match', content_type=CONTENT).source(['pk'])- .using(CLIENT)- .filter('match', content_type=CONTENT))+ .using(CLIENT))return [hit.pk for hit in search.execute()]def _make_host_entry(url):use_ssl = url.scheme == 'https'auth = (url.username, url.password)- http_auth = auth if all(auth) else Nonereturn {'host': url.hostname,'port': url.port or (443 if use_ssl else 80),'url_prefix': url.path,'use_ssl': use_ssl,'verify_certs': use_ssl,- 'http_auth': http_auth+ 'http_auth': auth if all(auth) else None}diff --git a/saleor/search/backends/test_newelastic.py b/saleor/search/backends/test_newelastic.pyindex ce78591226..8816e7145b 100644--- a/saleor/search/backends/test_newelastic.py+++ b/saleor/search/backends/test_newelastic.py@@ -11,16 +11,22 @@ def search_phrase():@pytest.fixturedef es_search_query(search_phrase):+ CONTENT_TYPE = 'product.Product'+ FIELDS = ['name', 'description']return {'query': {'bool': {'must': [{'multi_match': {- 'query': 'How fortunate man with none',- 'fields': ['name', 'description']+ 'fields': ['name', 'description'],+ 'query': 'How fortunate man with none'}}],'filter': [{+ 'term': {+ 'is_published_filter': True+ }+ }, {'match': {'content_type': 'product.Product'}@@ -36,8 +42,8 @@ def storefront_index():return 'storefront__product_product'-def test_no_result_search(mocker, es_search_query, search_phrase,- storefront_index):+def test_storefront_product_search_query_syntax(+ mocker, es_search_query, search_phrase, storefront_index):mocker.patch.object(newelastic.CLIENT, 'search', returnvalue=[])products = newelastic.search_products(search_phrase)newelastic.CLIENT.search.assert_called_once_with(