From af7fda8752f0829b950fecd9a8f3857b64d00aa3 Mon Sep 17 00:00:00 2001 From: Konstantinos Arvanitakis Date: Wed, 5 Aug 2026 23:09:52 +0300 Subject: [PATCH] Updating Prroduct Indexer --- src/Search/ProductIndexer.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Search/ProductIndexer.php b/src/Search/ProductIndexer.php index 29f4ae1..06b572b 100644 --- a/src/Search/ProductIndexer.php +++ b/src/Search/ProductIndexer.php @@ -9,9 +9,25 @@ use Lunar\Search\ProductIndexer as BaseProductIndexer; * Lunar's own indexer puts raw attribute HTML (e.g. name_en, description_en) into * the search index, which pollutes relevance ranking and highlighting with markup. * Strip tags from string fields before they reach Meilisearch. + * + * Also indexes channel_ids (Lunar's base indexer only indexes "status" as a + * filterable field, not channel), so the storefront can filter search + * results to products actually assigned+enabled on the current channel. + * + * After changing filterable/sortable fields here, settings must be re-synced: + * php artisan lunar:meilisearch:setup + * php artisan lunar:search:index "Lunar\Models\Product" --refresh */ class ProductIndexer extends BaseProductIndexer { + public function getFilterableFields(): array + { + return [ + ...parent::getFilterableFields(), + 'channel_ids', + ]; + } + public function toSearchableArray(Model $model): array { $data = parent::toSearchableArray($model); @@ -22,6 +38,11 @@ class ProductIndexer extends BaseProductIndexer } } + $data['channel_ids'] = $model->channels() + ->wherePivot('enabled', true) + ->pluck('id') + ->toArray(); + return $data; } }