From 3160ab45498e88a4deba130241a6d77a4c542a36 Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Sat, 21 Jun 2025 23:52:05 +0300 Subject: [PATCH] **Features**: 1) Add `score_mode="first"` to function_score query configuration for enhanced scoring; **Fixes**: None; **Extra**: 1) Wrap product-specific attributes like `rating` and `brand_priority` in a debug-mode conditional block; --- core/elasticsearch/__init__.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/core/elasticsearch/__init__.py b/core/elasticsearch/__init__.py index 14272c93..3d3e1e1f 100644 --- a/core/elasticsearch/__init__.py +++ b/core/elasticsearch/__init__.py @@ -79,7 +79,8 @@ def process_query(query: str = "", request: Request | None = None) -> dict[str, }, } ], - boost_mode="sum", + boost_mode="multiply", + score_mode="first", ) search = Search(index=["products", "categories", "brands", "posts"]).query(function_score_query).extra(size=100) @@ -121,9 +122,16 @@ def process_query(query: str = "", request: Request | None = None) -> dict[str, "image": image_url, } - if idx == "products": - hit_result["rating"] = getattr(hit, "rating", 0) - hit_result["brand_priority"] = getattr(hit, "brand_priority", 0) + if settings.DEBUG: + if idx == "products": + hit_result["rating"] = getattr(hit, "rating", 0) + hit_result["brand_priority"] = getattr(hit, "brand_priority", 0) + if idx == "brands": + pass + if idx == "categories": + pass + if idx == "posts": + pass results[idx].append(hit_result)