From 326e1fac54cdecfdf44a848405a29c6e0a1bb759 Mon Sep 17 00:00:00 2001 From: Konstantinos Arvanitakis Date: Wed, 23 Sep 2026 09:48:25 +0300 Subject: [PATCH] Updating search.php for indexing --- config/lunar/search.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/config/lunar/search.php b/config/lunar/search.php index e885456..8e38315 100644 --- a/config/lunar/search.php +++ b/config/lunar/search.php @@ -20,7 +20,17 @@ Lunar\Models\Collection::class, Lunar\Models\Customer::class, Lunar\Models\Order::class, - Lunar\Models\Product::class, + // Modules\Core\Catalog\Models\Product, not Lunar\Models\Product — + // both share the same underlying Meilisearch index name, so + // listing the base class here too would make every reindex + // (this default list is always merged in, even when a specific + // model is passed on the CLI — see Lunar\Console\Commands\ + // ScoutIndexerCommand::handle()) run the base class's indexing a + // second time right after the subclass's, silently overwriting + // every document with one missing custom_fields/order_count + // (the whole reason Modules\Core\Catalog\Models\Product exists — + // see its own docblock). Caught in practice. + Modules\Core\Catalog\Models\Product::class, Lunar\Models\ProductOption::class, /* @@ -49,6 +59,20 @@ Lunar\Models\Collection::class => Modules\Core\Catalog\Services\CollectionIndexer::class, Lunar\Models\Customer::class => Lunar\Search\CustomerIndexer::class, Lunar\Models\Order::class => Lunar\Search\OrderIndexer::class, + // Lunar\Models\Product::class, NOT Modules\Core\Catalog\Models\ + // Product::class — Lunar\Base\Traits\Searchable::indexer() (and + // getFilterableAttributes()/getSortableAttributes(), same trait) + // reads `$config[self::class]`, and `self::class` inside a TRAIT + // METHOD is a compile-time literal bound to whichever class first + // `use`s the trait — Lunar\Models\Product, since the subclass + // never re-declares indexer() itself — regardless of which + // instance actually calls the method at runtime. Keying this by + // the subclass here made the lookup miss entirely, silently + // falling back to Lunar\Search\ScoutIndexer's own near-empty + // filterable/sortable field list — confirmed live: it wiped every + // real filterable/sortable attribute the index had (including + // ones that already worked, like collection_ids), not just the + // new order_count one. Caught in practice, reverted. Lunar\Models\Product::class => Modules\Core\Catalog\Services\ProductIndexer::class, Lunar\Models\ProductOption::class => Lunar\Search\ProductOptionIndexer::class, ],