How do I add custom facets to listing and search?
In order to define facets against a document, you must first register the facet group. This should be done within the **boot()**method of a ServiceProvideror the **setup()**method of a module ServiceProvider.
\Aero\Search\FacetSettings::registerFacet('stock', 'Stock Status');
The document structure can then be extended to add the facet to the document’s data.
\Aero\Search\Elastic\Documents\ListingDocument::add('string-facets', function ($document) {
$stock = $document->getModel()->availableStock() > 0;
return [
\Aero\Search\Elastic\Facet::create('stock', 'Stock Status', (int) $stock, $stock ? 'In-stock' : 'Out of stock'),
];
});
Re-index the documents after any modifications to the document structure.