Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
(PC-8434) index subcategory id instead of label
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinewg committed Sep 23, 2021
1 parent bb82f8f commit e89aa8d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/pcapi/core/search/backends/algolia.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/pcapi/core/search/backends/appsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
OFFERS_ENGINE_NAME = "offers"

OFFERS_SCHEMA = {
"subcategory_label": "text",
"artist": "text",
"category": "text",
"date_created": "date",
Expand All @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions tests/core/search/test_serialize_algolia.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion tests/core/search/test_serialize_appsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down

0 comments on commit e89aa8d

Please sign in to comment.