Updating Prroduct Indexer
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user