Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Execute search query
Jakub Draganek08ff4730ad37
diff --git a/saleor/search/backends/newelastic.py b/saleor/search/backends/newelastic.pyindex 51026caea3..c596fd66c9 100644--- a/saleor/search/backends/newelastic.py+++ b/saleor/search/backends/newelastic.py@@ -1,8 +1,16 @@-import json+from elasticsearch import Elasticsearch+from elasticsearch_dsl import Search+from elasticsearch_dsl.query import MultiMatch+CLIENT = Elasticsearch()-def build_es_query():- return json.dumps({})++def search(phrase):+ result = (Search()+ .query(MultiMatch(query=phrase, fields=['name', 'description']))+ .using(CLIENT)+ .execute())+ return []class SearchBackend(object):@@ -11,5 +19,5 @@ class SearchBackend(object):def __init__(*args, **kwargs):pass- def search(self, query, model_or_queryset):- return []+ def search(self, query, model_or_queryset=None):+ passdiff --git a/saleor/search/backends/test_newelastic.py b/saleor/search/backends/test_newelastic.pyindex f94b886d5b..9dc715edf8 100644--- a/saleor/search/backends/test_newelastic.py+++ b/saleor/search/backends/test_newelastic.py@@ -1,7 +1,18 @@-import jsonfrom . import newelastic-def test_builds_json_query():- query = newelastic.build_es_query()- json.loads(query)+def test_search(mocker):+ mocker.patch.object(newelastic.CLIENT, 'search', returnvalue=[])+ phrase = 'foo'+ products = newelastic.search(phrase)+ expected_query = {+ 'query': {+ 'multi_match': {+ 'fields': ['name', 'description'],+ 'query': phrase+ }+ }+ }+ newelastic.CLIENT.search.assert_called_once_with(+ body=expected_query, doc_type=[], index=None)+ assert not products