Revert "Features: 1) Add top_level field to documents with preparation logic; 2) Add price field to documents with preparation logic; 3) Introduce score boosting with function_score using sales_rank field;"
This reverts commit 529fd39ff4.
This commit is contained in:
parent
e68bd73a6a
commit
e541dfd624
2 changed files with 1 additions and 32 deletions
|
|
@ -65,31 +65,9 @@ def process_query(query: str = "", request: Request | None = None):
|
|||
minimum_should_match=1,
|
||||
)
|
||||
|
||||
functions = [
|
||||
{
|
||||
"gauss": {
|
||||
"sales_rank": {
|
||||
"origin": 100,
|
||||
"scale": 500,
|
||||
"offset": 0,
|
||||
"decay": 0.3,
|
||||
}
|
||||
},
|
||||
"weight": 3,
|
||||
},
|
||||
]
|
||||
|
||||
boosted = Q(
|
||||
"function_score",
|
||||
query=q,
|
||||
boost_mode="sum",
|
||||
score_mode="sum",
|
||||
functions=functions,
|
||||
)
|
||||
|
||||
search = (
|
||||
Search(index=["products", "categories", "brands", "posts"])
|
||||
.query(boosted)
|
||||
.query(q)
|
||||
.extra(size=100)
|
||||
)
|
||||
response = search.execute()
|
||||
|
|
|
|||
|
|
@ -56,15 +56,6 @@ class ProductDocument(_BaseDoc):
|
|||
rating = fields.FloatField(attr="rating")
|
||||
product_type = fields.KeywordField()
|
||||
sales_rank = fields.IntegerField()
|
||||
top_level = fields.KeywordField()
|
||||
price = fields.FloatField()
|
||||
|
||||
def prepare_price(self, obj):
|
||||
return float(obj.price) if obj.price else 0.0
|
||||
|
||||
def prepare_top_level(self, obj):
|
||||
root = obj.category.get_root() if obj.category else None
|
||||
return root.slug if root else "other"
|
||||
|
||||
def prepare_product_type(self, obj):
|
||||
return obj.category.slug.split("-")[0] if obj.category else "other"
|
||||
|
|
|
|||
Loading…
Reference in a new issue