Overview
Search in Lunar is built on Laravel Scout, providing a flexible, driver-based search system. Scout’s database driver offers basic search out of the box, while more powerful engines like Meilisearch and Typesense can be swapped in for advanced features such as faceted filtering and relevance tuning. All search configuration lives inconfig/lunar/search.php. This file controls which models are indexed, which search engine each model uses, and which indexer class prepares the data for each model.
Configuration
Soft Deletes
By default, Scout sets thesoft_delete option to false. This must be set to true in config/scout.php, otherwise soft-deleted models will appear in search results.
Searchable Models
Themodels array in config/lunar/search.php defines which models are indexed. Lunar registers the following models by default:
Lunar\Base\Traits\Searchable trait.
Engine Mapping
By default, Scout uses the driver defined by theSCOUT_DRIVER environment variable for all models. This means if SCOUT_DRIVER is set to meilisearch, every searchable model gets indexed via Meilisearch.
This may not always be desirable. For example, indexing orders in a paid service like Algolia alongside products would unnecessarily increase record counts and cost. Lunar allows specifying a different driver per model using the engine_map configuration:
engine_map falls back to the default Scout driver.
Searchable Trait
All searchable Lunar models use theLunar\Base\Traits\Searchable trait. This trait extends Scout’s Searchable trait and delegates key behavior to an indexer class:
searchableAs()— returns the index nametoSearchableArray()— returns the data to indexshouldBeSearchable()— determines whether the model should be indexedsearchableUsing()— returns the engine based on theengine_mapconfigurationgetFilterableAttributes()— returns filterable fields for the enginegetSortableAttributes()— returns sortable fields for the engine
indexers config, falling back to the base Lunar\Search\ScoutIndexer if no specific indexer is mapped.
Indexers
Each searchable model is paired with an indexer class that controls what data is sent to the search engine. Theindexers config maps models to their indexer:
Default Indexer
The baseLunar\Search\ScoutIndexer class indexes:
- The model’s
id - Any attributes marked as
searchable
TranslatedText attribute fields, creating locale-suffixed entries (e.g., name_en, name_fr) in the index.
Product Indexer
TheLunar\Search\ProductIndexer indexes the following fields:
| Field | Source |
|---|---|
id | Product ID |
status | Product status |
product_type | Product type name |
brand | Brand name (if present) |
created_at | Unix timestamp |
thumbnail | Thumbnail URL (small variant) |
skus | Array of variant SKUs |
| Attribute handles | Values from searchable attributes |
created_at, updated_at, skus, status
Filterable fields: __soft_deleted, skus, status
Order Indexer
TheLunar\Search\OrderIndexer indexes the following fields:
| Field | Source |
|---|---|
id | Order ID |
channel | Channel name |
reference | Order reference |
customer_reference | Customer reference |
status | Order status |
placed_at | Placement timestamp |
created_at | Unix timestamp |
sub_total | Sub-total value |
total | Total value |
currency_code | Currency code |
charges | Transaction references |
lines | Product line descriptions and identifiers |
{type}_first_name, {type}_last_name, etc. | Address fields prefixed by type (shipping/billing) |
tags | Array of tag values |
customer_id, user_id, channel_id, created_at, updated_at, total
Filterable fields: customer_id, user_id, status, placed_at, channel_id, tags, __soft_deleted
Customer Indexer
TheLunar\Search\CustomerIndexer indexes the following fields:
| Field | Source |
|---|---|
id | Customer ID |
name | Full name |
company_name | Company name |
tax_identifier | Tax identifier |
account_ref | Account reference |
created_at | Unix timestamp |
user_emails | Array of associated user emails |
| Meta fields | Any meta key-value pairs |
| Attribute handles | Values from searchable attributes |
created_at, updated_at, name, company_name
Filterable fields: __soft_deleted, name, company_name
Brand Indexer
TheLunar\Search\BrandIndexer indexes the following fields:
| Field | Source |
|---|---|
id | Brand ID |
name | Brand name |
created_at | Unix timestamp |
| Attribute handles | Values from searchable attributes |
created_at, updated_at, name
Filterable fields: __soft_deleted, name
Collection Indexer
TheLunar\Search\CollectionIndexer indexes the following fields:
| Field | Source |
|---|---|
id | Collection ID |
created_at | Unix timestamp |
| Attribute handles | Values from searchable attributes |
created_at, updated_at, name
Filterable fields: __soft_deleted, name
ProductOption Indexer
TheLunar\Search\ProductOptionIndexer indexes the following fields:
| Field | Source |
|---|---|
id | ProductOption ID |
name_{locale} | Option name per locale |
label_{locale} | Option label per locale |
option_{id}_{locale} | Option value names per locale |
created_at, updated_at
Filterable fields: __soft_deleted
Indexing Records
To import or refresh search indexes, use thelunar:search:index artisan command:
models configuration.
Command Options
| Option | Description |
|---|---|
models | One or more model class names to index (space-separated). Merged with config models by default. |
--ignore | Only index the models specified in the command, ignoring the config file. |
--refresh | Delete existing records from the index before reimporting. |
--flush | Delete records from the index without reimporting. Cannot be combined with --refresh. |
Meilisearch Setup
When using Meilisearch, run the setup command to configure filterable and sortable attributes on Meilisearch indexes:Storefront Search Add-on
For storefront search features such as faceted filtering, sorting, pagination, and structured response data, install the Storefront Search add-on:Search facade with support for Meilisearch, Typesense, and database drivers, returning consistent SearchResults objects with hits, facets, and pagination.