Search indexing can be extended to customize searchable, sortable, and filterable fields.Documentation Index
Fetch the complete documentation index at: https://docs.lunarphp.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Good search is the backbone of any storefront, so Lunar aims to make this as extensible as possible. Custom fields can be indexed for the storefront without compromising what Lunar requires for the admin panel. There are three things to consider when you want to extend the search:- Searchable fields
- Sortable fields
- Filterable fields
Default index values
Eloquent models which use theLunar\Base\Traits\Searchable trait will use an indexer class to tell Scout how each model
should be indexed. If an indexer isn’t mapped in the config, the default ScoutIndexer (provided by Lunar) will be
used.
This class will map a basic set of fields to the search index:
- The ID of the model
- Any
searchableattributes.
Lunar\Search\ProductIndexer
Fields which are indexed:
- The ID of the model
- Any
searchableattributes. - The product
status - The product
product_type - The
brand(if applicable) - The ProductVariant
skusrelated to the product. - The
created_attimestamp
Mapping custom indexers
All indexers are mapped inconfig/lunar/search.php under indexers. If a model isn’t mapped here, the default
ScoutIndexer is used. To change how each model is indexed, map it like so:
Creating a custom indexer
To create your own indexer, simply create a custom class like so:ScoutIndexer class implements the Lunar\Search\Interfaces\ScoutIndexerInterface interface. If a custom indexer
does not extend ScoutIndexer, it must implement this interface directly.
There are some methods which are available on ScoutIndexer but not defined on the interface:
mapSearchableAttributes
searchable attributes for the model attribute type and map them into the index,
this means when you add searchable attributes in the hub they will automatically be added to the index.