Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Clean old backend remains

Jakub Draganek23d93ffab2f1
diff --git a/saleor/search/backends/newelastic.py b/saleor/search/backends/newelastic.py
index e3497e0b51..6fa2c228c8 100644
--- a/saleor/search/backends/newelastic.py
+++ b/saleor/search/backends/newelastic.py
@@ -1,37 +1,21 @@
from __future__ import unicode_literals
-from elasticsearch import Elasticsearch
-from django.utils.six.moves.urllib.parse import urlparse
from django.db.models.query import QuerySet
from elasticsearch_dsl.query import MultiMatch
from ..documents import ProductDocument
-def _make_host_entry(url):
- use_ssl = url.scheme == 'https'
- auth = (url.username, url.password)
- return {
- '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': auth if all(auth) else None
- }
-
-
-def _get_es_hosts(params):
- hosts = params.pop('HOSTS', [])
- es_urls = map(urlparse, params.pop('URLS', []))
- return hosts + [_make_host_entry(url) for url in es_urls]
-
+def search_products(phrase):
+ ''' Execute external search for product matching phrase '''
+ query = MultiMatch(fields=['name', 'description'], query=phrase)
+ search = (ProductDocument.search()
+ .query(query)
+ .source(False)
+ .filter('term', is_published=True))
+ return [hit.meta.id for hit in search.execute()]
-class SearchBackend(object):
- rebuilder_class = None
- client = None
- @staticmethod
- def search(query, model_or_queryset):
+def search(query, model_or_queryset):
qs = model_or_queryset
# TODO: remove this ugly type incoherence of old search api
if not isinstance(model_or_queryset, QuerySet):
@@ -39,11 +23,4 @@ class SearchBackend(object):
return qs.filter(pk__in=search_products(query))
-def search_products(phrase):
- ''' Execute external search for product matching phrase '''
- query = MultiMatch(fields=['name', 'description'], query=phrase)
- search = (ProductDocument.search()
- .query(query)
- .source(False)
- .filter('term', is_published=True))
- return [hit.meta.id for hit in search.execute()]
+
diff --git a/saleor/search/forms.py b/saleor/search/forms.py
index f06620396a..e8a1d8f2a8 100644
--- a/saleor/search/forms.py
+++ b/saleor/search/forms.py
@@ -8,6 +8,4 @@ class SearchForm(forms.Form):
label=pgettext('Search form label', 'Query'), required=True)
def search(self, model_or_queryset):
- results = newelastic.SearchBackend.search(self.cleaned_data['q'],
- model_or_queryset)
- return results
+ return newelastic.search(self.cleaned_data['q'], model_or_queryset)
diff --git a/tests/test_search.py b/tests/test_search.py
index b1471b616c..907f6f600a 100644
--- a/tests/test_search.py
+++ b/tests/test_search.py
@@ -9,6 +9,7 @@ MATCH_SEARCH_REQUEST = ['method', 'host', 'port', 'path', 'body']
NEW_BACKEND_FOUND = {15, 34, 58} # same as in recorded data!
PRODUCTS_INDEXED = NEW_BACKEND_FOUND
@pytest.fixture
def indexed_products(product_class, default_category):
''' Products to be found by search backend
@@ -33,18 +34,9 @@ def _extract_pks(object_list):
return [prod.pk for prod, _ in object_list]
-def new_search_backend():
- import saleor.search.forms
- old_backend = saleor.search.forms.USE_BACKEND
- saleor.search.forms.USE_BACKEND = 'newelastic'
- yield new_search_backend
- saleor.search.forms.USE_BACKEND = old_backend
-
-
@pytest.mark.integration
@pytest.mark.vcr(record_mode='once', match_on=MATCH_SEARCH_REQUEST)
-def test_new_search_with_empty_results(db, client, new_search_backend):
+def test_new_search_with_empty_results(db, client):
''' no products found with foo '''
WORD = 'foo'
response = client.get(reverse('search:search'), {'q': WORD})
@@ -54,8 +46,7 @@ def test_new_search_with_empty_results(db, client, new_search_backend):
@pytest.mark.integration
@pytest.mark.vcr(record_mode='once', match_on=MATCH_SEARCH_REQUEST)
-def test_new_search_with_result(db, indexed_products, client,
- new_search_backend):
+def test_new_search_with_result(db, indexed_products, client):
''' some products founds, only those both in search result and objects '''
EXISTING_PHRASE = 'Group'
response = client.get(reverse('search:search'), {'q': EXISTING_PHRASE})
@@ -79,7 +70,7 @@ def products_with_mixed_publishing(indexed_products):
@pytest.mark.integration
@pytest.mark.vcr(record_mode='once', match_on=MATCH_SEARCH_REQUEST)
def test_new_search_doesnt_show_unpublished(db, products_with_mixed_publishing,
- client, new_search_backend):
+ client):
published_products = NEW_BACKEND_FOUND - PRODUCTS_TO_UNPUBLISH
EXISTING_PHRASE = 'Group'
response = client.get(reverse('search:search'), {'q': EXISTING_PHRASE})