How can I extend the document structure?
To extend a document, use the add() method, to define a closure that will return an array of data to merge into the document structure:
\Aero\Search\Elastic\Documents\ListingDocument::add('search-result', function ($document) {
$colors = $document->getModel()
->visibleVariants()
->pluck('attributes')
->flatten()
->filter(function ($attribute) {
return strpos(strtolower($attribute->group->name), 'color') !== false;
})
->pluck('name')
->unique()
->values()
->all();
return [
'colors' => $colors,
];
});