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 so you can index what you need for your front-end, without compromising on what we require our side in the hub. 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 it
should be indexed, if an indexer isn’t mapped in the config the default EloquentIndexer (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/search.php under indexers, if a model isn’t mapped here then it will
simply use the default ELoquentIndexer. To change how each model is indexed, simply map it like so:
Creating a custom indexer
To create your own indexer, simply create a custom class like so:EloquentIndexer class implements the Lunar\Search\Interfaces\ModelIndexerInterface so if your class doesn’t
extend the Eloquent one, you must implement this interface.
There are some methods which are available just on the EloquentIndexer but not defined on the interface are:
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.