Commit 9a233f6c authored by Vũ Hoàng Anh's avatar Vũ Hoàng Anh

fix(search): replace non-existent outfit_recommendations with similar_items in SearchEngine query

parent 075c9528
......@@ -45,7 +45,7 @@ SELECT_COLUMNS = """
size_scale,
description_text,
tags,
outfit_recommendations,
similar_items,
description_text_full
"""
......@@ -333,17 +333,17 @@ class SearchEngine:
return [], 0, "No results found"
@staticmethod
def _parse_outfit_recommendations(products: list) -> list:
"""Parse outfit_recommendations JSON string from One Big Table into list[dict]."""
def _parse_similar_items(products: list) -> list:
"""Parse similar_items JSON string from One Big Table into list[dict]."""
for p in products:
raw = p.get("outfit_recommendations")
raw = p.get("similar_items")
if raw and isinstance(raw, str):
try:
p["outfit_recommendations"] = json.loads(raw)
p["similar_items"] = json.loads(raw)
except (json.JSONDecodeError, TypeError):
p["outfit_recommendations"] = []
p["similar_items"] = []
elif not raw:
p["outfit_recommendations"] = []
p["similar_items"] = []
return products
async def search(self, literal: str, inferred: Dict[str, Any], check_stock: bool = True) -> Dict[str, Any]:
......@@ -363,7 +363,7 @@ class SearchEngine:
if products:
if check_stock: products = await enrich_with_stock(products)
products = self._parse_outfit_recommendations(products)
products = self._parse_similar_items(products)
for p in products:
raw_size = p.get("size_scale", "")
parsed = [s.strip() for s in str(raw_size).replace("[", "").replace("]", "").replace('"', '').split(",") if s.strip()]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment