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

feat(search): retrieve and parse both similar_items and outfit_recommendations

parent 9a233f6c
......@@ -46,6 +46,7 @@ SELECT_COLUMNS = """
description_text,
tags,
similar_items,
outfit_recommendations,
description_text_full
"""
......@@ -346,6 +347,20 @@ class SearchEngine:
p["similar_items"] = []
return products
@staticmethod
def _parse_outfit_recommendations(products: list) -> list:
"""Parse outfit_recommendations JSON string from One Big Table into list[dict]."""
for p in products:
raw = p.get("outfit_recommendations")
if raw and isinstance(raw, str):
try:
p["outfit_recommendations"] = json.loads(raw)
except (json.JSONDecodeError, TypeError):
p["outfit_recommendations"] = []
elif not raw:
p["outfit_recommendations"] = []
return products
async def search(self, literal: str, inferred: Dict[str, Any], check_stock: bool = True) -> Dict[str, Any]:
inf = InferredSearch(**inferred)
_apply_event_fallback(inf, literal)
......@@ -364,6 +379,7 @@ class SearchEngine:
if products:
if check_stock: products = await enrich_with_stock(products)
products = self._parse_similar_items(products)
products = self._parse_outfit_recommendations(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