diff --git a/core/elasticsearch/__init__.py b/core/elasticsearch/__init__.py index 898cc6ac..56908143 100644 --- a/core/elasticsearch/__init__.py +++ b/core/elasticsearch/__init__.py @@ -33,7 +33,9 @@ SMART_FIELDS = [ ] -def process_query(query: str = "", request: Request | None = None): +def process_query( + query: str = "", request: Request | None = None +) -> dict[str, list[dict]] | None: """ Perform a lenient, typo‑tolerant, multi‑index search. @@ -120,14 +122,18 @@ def process_query(query: str = "", request: Request | None = None): if cat.image: image_url = request.build_absolute_uri(cat.image.url) - results[idx].append( - { - "uuid": str(obj_uuid), - "name": obj_name, - "slug": obj_slug, - "image": image_url, - } - ) + hit_result = { + "uuid": str(obj_uuid), + "name": obj_name, + "slug": obj_slug, + "image": image_url, + } + + if idx == "products": + hit_result["rating"] = getattr(hit, "rating", 0) + hit_result["brand_priority"] = getattr(hit, "brand_priority", 0) + + results[idx].append(hit_result) return results except NotFoundError: diff --git a/core/migrations/0032_alter_brand_slug_alter_category_slug_and_more.py b/core/migrations/0032_alter_brand_slug_alter_category_slug_and_more.py new file mode 100644 index 00000000..237c5935 --- /dev/null +++ b/core/migrations/0032_alter_brand_slug_alter_category_slug_and_more.py @@ -0,0 +1,57 @@ +# Generated by Django 5.2 on 2025-06-21 17:14 + +import django_extensions.db.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("core", "0031_alter_product_slug"), + ] + + operations = [ + migrations.AlterField( + model_name="brand", + name="slug", + field=django_extensions.db.fields.AutoSlugField( + allow_unicode=True, + blank=True, + editable=False, + max_length=88, + null=True, + overwrite=True, + populate_from=("name",), + unique=True, + verbose_name="brand slug", + ), + ), + migrations.AlterField( + model_name="category", + name="slug", + field=django_extensions.db.fields.AutoSlugField( + allow_unicode=True, + blank=True, + editable=False, + max_length=88, + null=True, + overwrite=True, + populate_from=("uuid", "name"), + unique=True, + ), + ), + migrations.AlterField( + model_name="product", + name="slug", + field=django_extensions.db.fields.AutoSlugField( + allow_unicode=True, + blank=True, + editable=False, + max_length=88, + null=True, + overwrite=True, + populate_from=("name", "brand__slug", "category__slug", "uuid"), + unique=True, + ), + ), + ] diff --git a/core/models.py b/core/models.py index 47336b51..17658b3a 100644 --- a/core/models.py +++ b/core/models.py @@ -221,6 +221,8 @@ class Category(ExportModelOperationsMixin("category"), NiceModel, MPTTModel): allow_unicode=True, unique=True, editable=False, + max_length=88, + overwrite=True, null=True, ) tags: CategoryTag = ManyToManyField( # type: ignore @@ -289,6 +291,8 @@ class Brand(ExportModelOperationsMixin("brand"), NiceModel): allow_unicode=True, unique=True, editable=False, + max_length=88, + overwrite=True, null=True, verbose_name=_("brand slug"), ) @@ -364,6 +368,8 @@ class Product(ExportModelOperationsMixin("product"), NiceModel): "category__slug", "uuid", ), + max_length=88, + overwrite=True, allow_unicode=True, unique=True, editable=False,