Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson committed Jan 16, 2025
1 parent 9d108c8 commit 52ec3f8
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions packages/search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,29 @@ composer require lunarphp/search

## Usage

### Configuration

Most configuration is done via `config/lunar/search.php`. Here you can specify which facets should be used and how they are displayed.

```php
'facets' => [
\Lunar\Models\Product::class => [
'brand' => [
'label' => 'Brand',
],
'colour' => [
'label' => 'Colour',
],
'size' => [
'label' => 'Size',
],
'shoe-size' => [
'label' => 'Shoe Size',
]
]
],
```

### Basic Search

At a basic level, you can search models using the provided facade.
Expand All @@ -40,3 +63,37 @@ then perform a search using that given driver. To increase performance the resul
hydrated from the database, but instead will be the raw results from the search provider.


### Handling the response

Searching returns a `Lunar\Data\SearchResult` DTO which you can use in your templates:

```php
use Lunar\Search\Facades\Search;
$results = Search::query('Hoodies')->get();
```

```bladehtml
<!-- Loop through results-->
@foreach($results->hits as $hit)
{{ $hit->document['name'] }}
@endforeach
<!-- Loop through facets -->
@foreach($results->facets as $facet)
<span>
<strong>{{ $facet->label }}</strong>
@foreach($facet->values as $facetValue)
<input type="checkbox" value="{{ $facetValue->value }}" />
<span
@class([
'text-blue-500' => $facetValue->active,
])
>
{{ $facetValue->label }}
</span>
{{ $facetValue->count }}
@endforeach
</div>
@endforeach
```

0 comments on commit 52ec3f8

Please sign in to comment.