Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Drop elasticsearch
IKarbowiak39344b61f13d
diff --git a/.isort.cfg b/.isort.cfgindex 0673165885..049ebdc9d4 100644--- a/.isort.cfg+++ b/.isort.cfg@@ -1,2 +1,2 @@[settings]-known_third_party = PIL,babel,bleach,bootstrap4,braintree,celery,dj_database_url,dj_email_url,django,django_babel,django_cache_url,django_countries,django_elasticsearch_dsl,django_filters,django_measurement,django_prices,django_prices_openexchangerates,django_prices_vatlayer,draftjs_sanitizer,elasticsearch_dsl,faker,freezegun,geolite2,google_measurement_protocol,graphene,graphene_django,graphene_django_optimizer,graphene_federation,graphql,graphql_jwt,graphql_relay,html5lib,html_to_draftjs,i18naddress,markdown,measurement,mptt,oauthlib,phonenumber_field,phonenumbers,prices,promise,pytest,razorpay,requests,sentry_sdk,six,social_core,storages,stripe,templated_email,text_unidecode,tqdm,versatileimagefield+known_third_party = PIL,babel,bleach,bootstrap4,braintree,celery,dj_database_url,dj_email_url,django,django_babel,django_cache_url,django_countries,django_filters,django_measurement,django_prices,django_prices_openexchangerates,django_prices_vatlayer,draftjs_sanitizer,faker,freezegun,geolite2,google_measurement_protocol,graphene,graphene_django,graphene_django_optimizer,graphene_federation,graphql,graphql_jwt,graphql_relay,html5lib,html_to_draftjs,i18naddress,markdown,measurement,mptt,oauthlib,phonenumber_field,phonenumbers,prices,promise,pytest,razorpay,requests,sentry_sdk,six,social_core,storages,stripe,templated_email,text_unidecode,tqdm,versatileimagefielddiff --git a/saleor/search/backends/elasticsearch.py b/saleor/search/backends/elasticsearch.pydeleted file mode 100644index 627dfc8a6f..0000000000--- a/saleor/search/backends/elasticsearch.py+++ /dev/null@@ -1,5 +0,0 @@-from . import elasticsearch_storefront---def search_storefront(phrase):- return elasticsearch_storefront.search(phrase)diff --git a/saleor/search/backends/elasticsearch_storefront.py b/saleor/search/backends/elasticsearch_storefront.pydeleted file mode 100644index 1463218bf3..0000000000--- a/saleor/search/backends/elasticsearch_storefront.py+++ /dev/null@@ -1,18 +0,0 @@-from elasticsearch_dsl.query import MultiMatch--from ..documents import ProductDocument---def get_search_query(phrase):- """Return matching products for storefront views."""- query = MultiMatch(fields=["title", "name", "description"], query=phrase)- return (- ProductDocument.search()- .query(query)- .source(False)- .filter("term", is_published=True)- )---def search(phrase):- return get_search_query(phrase).to_queryset()diff --git a/saleor/search/backends/test_elasticsearch_storefront.py b/saleor/search/backends/test_elasticsearch_storefront.pydeleted file mode 100644index 4c54013e25..0000000000--- a/saleor/search/backends/test_elasticsearch_storefront.py+++ /dev/null@@ -1,19 +0,0 @@-from . import elasticsearch_storefront--PHRASE = "How fortunate man with none"-FIELDS = ["title", "name", "description"]-INDEX = "storefront"-DOC_TYPE = "doc"-QUERY = {- "_source": False,- "query": {- "bool": {- "must": [{"multi_match": {"query": PHRASE, "fields": FIELDS}}],- "filter": [{"term": {"is_published": True}}],- }- },-}---def test_storefront_product_search_query_syntax():- assert QUERY == elasticsearch_storefront.get_search_query(PHRASE).to_dict()diff --git a/saleor/search/documents.py b/saleor/search/documents.pydeleted file mode 100644index b794f0cfa3..0000000000--- a/saleor/search/documents.py+++ /dev/null@@ -1,30 +0,0 @@-from django_elasticsearch_dsl import DocType, Index, fields-from elasticsearch_dsl import analyzer, token_filter--from ..product.models import Product--storefront = Index("storefront")-storefront.settings(number_of_shards=1, number_of_replicas=0)---partial_words = token_filter("partial_words", "edge_ngram", min_gram=3, max_gram=15)-title_analyzer = analyzer(- "title_analyzer", tokenizer="standard", filter=[partial_words, "lowercase"]-)-email_analyzer = analyzer("email_analyzer", tokenizer="uax_url_email")--[email protected]_type-class ProductDocument(DocType):- title = fields.StringField(analyzer=title_analyzer)-- def prepare_title(self, instance):- return instance.name-- class Meta:- model = Product- fields = ["name", "description", "is_published"]---users = Index("users")-users.settings(number_of_shards=1, number_of_replicas=0)diff --git a/tests/test_elasticsearch.py b/tests/test_elasticsearch.pydeleted file mode 100644index 353473cef7..0000000000--- a/tests/test_elasticsearch.py+++ /dev/null@@ -1,95 +0,0 @@-import pytest-from elasticsearch_dsl.connections import connections-from prices import Money--from saleor.product.models import Product-from saleor.search.backends.elasticsearch import search_storefront--MATCH_SEARCH_REQUEST = ["method", "host", "port", "path"]-STOREFRONT_PRODUCTS = {15, 56} # same as in recorded data!-DASHBOARD_PRODUCTS = {58, 56}-PRODUCTS_INDEXED = STOREFRONT_PRODUCTS | DASHBOARD_PRODUCTS-PRODUCTS_TO_UNPUBLISH = {56} # choose from PRODUCTS_INDEXED-PHRASE_WITH_RESULTS = "Group"-PHRASE_WITHOUT_RESULTS = "foo"--ES_URL = "http://search:9200" # make it real for communication recording--[email protected](scope="module", autouse=True)-def elasticsearch_connection():- connections.create_connection("default", hosts=[ES_URL])--[email protected](scope="function", autouse=True)-def elasticsearch_enabled(settings):- settings.ES_URL = ES_URL- settings.ENABLE_SEARCH = True- settings.SEARCH_BACKEND = "saleor.search.backends.elasticsearch"--[email protected](scope="function", autouse=True)-def elasticsearch_autosync_disabled(settings):- """Prevent ES index from being refreshed every time objects are saved."""- settings.ELASTICSEARCH_DSL_AUTO_REFRESH = False- settings.ELASTICSEARCH_DSL_AUTOSYNC = False---def indexed_products(product_type, category):- """Products to be found by search backend.-- We need existing objects with primary keys same as search service- returned in response. Otherwise search view won't find anything.- Purpose of this fixture is for integration with search service only!- pks must be in response in appropiate recorded cassette.- """-- def gen_product_with_id(object_id):- product = Product.objects.create(- pk=object_id,- name="Test product " + str(object_id),- price=Money(10, "USD"),- product_type=product_type,- category=category,- is_published=True,- )- return product-- return [gen_product_with_id(prod) for prod in PRODUCTS_INDEXED]---def execute_search(phrase):- response = search_storefront(phrase)- return response.values_list("pk", flat=True)--[email protected](record_mode="once", match_on=MATCH_SEARCH_REQUEST)-def test_new_search_with_empty_results(db):- assert 0 == len(execute_search(PHRASE_WITHOUT_RESULTS))--[email protected](record_mode="once", match_on=MATCH_SEARCH_REQUEST)-def test_new_search_with_result(db, indexed_products):- found_products = execute_search(PHRASE_WITH_RESULTS)- assert STOREFRONT_PRODUCTS == set(found_products)---def products_with_mixed_publishing(indexed_products):- products_to_unpublish = Product.objects.filter(pk__in=PRODUCTS_TO_UNPUBLISH)- for prod in products_to_unpublish:- prod.is_published = False- prod.save()- return indexed_products--[email protected](record_mode="once", match_on=MATCH_SEARCH_REQUEST)-def test_new_search_doesnt_show_unpublished(db, products_with_mixed_publishing):- published_products = STOREFRONT_PRODUCTS - PRODUCTS_TO_UNPUBLISH- found_products = execute_search(PHRASE_WITH_RESULTS)- assert published_products == set(found_products)