diff --git a/src/pcapi/core/search/backends/algolia.py b/src/pcapi/core/search/backends/algolia.py index e6f156e838..dc7634f0bf 100644 --- a/src/pcapi/core/search/backends/algolia.py +++ b/src/pcapi/core/search/backends/algolia.py @@ -234,7 +234,6 @@ def serialize_offer(cls, offer: offers_models.Offer) -> dict: object_to_index = { "objectID": offer.id, "offer": { - "subcategoryLabel": offer.subcategory.app_label, "author": author, "category": offer.offer_category_name_for_app, "rankingWeight": offer.rankingWeight, @@ -264,6 +263,7 @@ def serialize_offer(cls, offer: offers_models.Offer) -> dict: "speaker": speaker, "stageDirector": stage_director, "stocksDateCreated": sorted(stocks_date_created), + "subcategoryId": offer.subcategory.id, # PC-8526: Warning: we should not store the full url of the image but only the path. # Currrently we store `OBJECT_STORAGE_URL/path`, but we should store `path` and build the # full url in the frontend. diff --git a/src/pcapi/core/search/backends/appsearch.py b/src/pcapi/core/search/backends/appsearch.py index 638637d9ab..034e57a5c4 100644 --- a/src/pcapi/core/search/backends/appsearch.py +++ b/src/pcapi/core/search/backends/appsearch.py @@ -34,7 +34,6 @@ OFFERS_ENGINE_NAME = "offers" OFFERS_SCHEMA = { - "subcategory_label": "text", "artist": "text", "category": "text", "date_created": "date", @@ -54,6 +53,7 @@ "ranking_weight": "number", "search_group_name": "text", "stocks_date_created": "date", + "subcategory_id": "text", "tags": "text", "times": "number", "thumb_url": "text", @@ -69,7 +69,7 @@ "category": 0, "label": 0, "search_group_name": 0, - "subcategory_label": 0, + "subcategory_id": 0, "tags": 0, "thumb_url": 0, "venue_department_code": 0, @@ -367,7 +367,6 @@ def serialize_offer(cls, offer: offers_models.Offer) -> dict: venue = offer.venue return omit_empty_values( { - "subcategory_label": offer.subcategory.app_label, "artist": artist.strip() or None, "category": offer.offer_category_name_for_app, "date_created": offer.dateCreated, # used only to rank results @@ -386,6 +385,7 @@ def serialize_offer(cls, offer: offers_models.Offer) -> dict: "ranking_weight": offer.rankingWeight or 0, "search_group_name": offer.subcategory.search_group_name, "stocks_date_created": [stock.dateCreated for stock in stocks], + "subcategory_id": offer.subcategory.id, "tags": [criterion.name for criterion in offer.criteria], "times": times, "thumb_url": url_path(offer.thumbUrl), diff --git a/tests/core/search/test_serialize_algolia.py b/tests/core/search/test_serialize_algolia.py index 88923d3a24..7f8887ca07 100644 --- a/tests/core/search/test_serialize_algolia.py +++ b/tests/core/search/test_serialize_algolia.py @@ -95,7 +95,6 @@ def test_should_return_algolia_object_with_required_information(self, app): assert result == { "objectID": 3, "offer": { - "subcategoryLabel": "Autre type d'événement musical", "author": None, "category": "MUSIQUE", "dateCreated": 1577872800.0, @@ -125,6 +124,7 @@ def test_should_return_algolia_object_with_required_information(self, app): "speaker": None, "stageDirector": None, "stocksDateCreated": [1606820400.0, 1607166000.0, 1607673600.0], + "subcategoryId": subcategories.EVENEMENT_MUSIQUE.id, "thumbUrl": f"http://localhost/storage/thumbs/products/{humanized_product_id}", "tags": [], "times": [32400], @@ -461,7 +461,6 @@ def test_should_return_algolia_object_with_one_tag_when_one_criterion(self, app) assert result == { "objectID": 3, "offer": { - "subcategoryLabel": "Autre type d'événement musical", "author": None, "category": "MUSIQUE", "dateCreated": 1577872800.0, @@ -491,6 +490,7 @@ def test_should_return_algolia_object_with_one_tag_when_one_criterion(self, app) "speaker": None, "stageDirector": None, "stocksDateCreated": [1607166000.0], + "subcategoryId": subcategories.EVENEMENT_MUSIQUE.id, "thumbUrl": f"http://localhost/storage/thumbs/products/{humanized_product_id}", "tags": ["Mon tag associé"], "times": [32400], @@ -556,7 +556,6 @@ def test_should_return_algolia_object_with_two_tags_when_two_criterion(self, app assert result == { "objectID": 3, "offer": { - "subcategoryLabel": "Autre type d'événement musical", "author": None, "category": "MUSIQUE", "dateCreated": 1577872800.0, @@ -586,6 +585,7 @@ def test_should_return_algolia_object_with_two_tags_when_two_criterion(self, app "speaker": None, "stageDirector": None, "stocksDateCreated": [1607166000.0], + "subcategoryId": subcategories.EVENEMENT_MUSIQUE.id, "thumbUrl": f"http://localhost/storage/thumbs/products/{humanized_product_id}", "tags": {"Mon tag associé", "Iron Man mon super héros"}, "times": [32400], diff --git a/tests/core/search/test_serialize_appsearch.py b/tests/core/search/test_serialize_appsearch.py index 826c445a0b..3bf27f2a1f 100644 --- a/tests/core/search/test_serialize_appsearch.py +++ b/tests/core/search/test_serialize_appsearch.py @@ -38,7 +38,6 @@ def test_serialize_offer(): stock = offers_factories.StockFactory(offer=offer, price=10) serialized = appsearch.AppSearchBackend().serialize_offer(offer) assert serialized == { - "subcategory_label": "Livre", "artist": "Author Performer Speaker Stage Director", "category": "LIVRE", "date_created": offer.dateCreated, @@ -56,6 +55,7 @@ def test_serialize_offer(): "ranking_weight": 2, "search_group_name": subcategories.SearchGroups.LIVRE.name, "stocks_date_created": [stock.dateCreated], + "subcategory_id": subcategories.LIVRE_PAPIER.id, "offerer_name": "Les Librairies Associées", "venue_id": 127, "venue_department_code": "75",