Overview
The Storefront Search add-on provides a unified API for performing search operations across multiple search engines. It wraps Laravel Scout and adds support for faceted search, filtering, sorting, and consistent response formatting using Spatie Laravel Data.Supported Engines
Installation
Require the composer package
Configuration
Publish and customize the configuration by creating or editingconfig/lunar/search.php. The add-on configuration controls which facets are available for each model:
label property is optional and defaults to the field name if not provided.
Usage
Basic Search
Search models using theSearch facade. By default, searches are performed against Lunar\Models\Product:
model() method:
engine_map configuration and performs the search using that driver. To improve performance, results are not hydrated from the database — instead, the raw indexed data is returned directly from the search provider.
Specifying a Driver
To explicitly use a specific search driver, call thedriver() method:
Filtering
Apply filters to narrow down search results. Filters are passed as key-value pairs where the key is the field name and the value is the filter value:Faceted Search
Facets allow users to refine search results by selecting values within categories (e.g., brand, color, size). Set active facet selections usingsetFacets():
Sorting
Sort results by a specific field:field:direction where direction is either asc or desc. The field must be configured as sortable in the search engine.
For Typesense, a raw sort expression can also be used:
Pagination
Control the number of results per page using theperPage() method. The default is 50:
Extending Queries
For advanced use cases, extend the search query usingextendQuery():
Response Format
All search engines return aLunar\Search\Data\SearchResults object with a consistent structure:
SearchHit
Each hit contains the indexed document data and any highlights (Typesense only):SearchHitHighlight
SearchFacet
SearchFacetValue
Handling the Response
Displaying Results
Displaying Facets
Pagination
Thelinks property contains a standard Laravel pagination view:
Accessing Pagination Metadata
TypeScript Integration
If Spatie TypeScript Transformer is being used, add the data path to thetypescript-transformer.php config to generate TypeScript types for the search response classes:
Lunar.Search namespace: