Updating search.php for indexing

This commit is contained in:
2026-09-23 09:48:25 +03:00
parent e3a6267059
commit 326e1fac54
+25 -1
View File
@@ -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,
],