Feature: Adding Facets, Updating Indexers
This commit is contained in:
@@ -21,6 +21,8 @@ nowhere near enough for a storefront category page or a nav tree.
|
||||
| `collection_group_id` | `$model->collection_group_id` | Filterable. Mirrors `Collection::scopeInGroup()`. |
|
||||
| `slugs` | `$model->urls->pluck('slug')` | Filterable. Every locale's `Url::slug`, so `getBySlug()` resolves purely from the index. |
|
||||
| `thumbnail` | `$model->getThumbnailImage()` | Display only. `null` if the collection has no thumbnail image. |
|
||||
| `ancestors` | `$model->ancestors` | Display only. Array of `{id, name}`, ordered root-first — a breadcrumb (`Home > Apparel > Keychains`) can render directly from a single `getById()`/`getBySlug()` call, no extra queries. Empty array for a top-level collection. |
|
||||
| `product_count` | Queried from the *product* Meilisearch index at collection-index time | Display only. How many products are in this collection **or any of its descendants** — matches what `ProductService::list(ProductFilters(collectionId: ...))` would return, not just direct assignment. Computed via `Product::search('')->options(['filter' => "collection_ids = \"{id}\""])`, so it depends on the product index already being current — reindex products *before* collections (see "Gotchas" below). |
|
||||
|
||||
`name`/`description` (and any other `TranslatedText` attribute) are indexed per-locale
|
||||
by Lunar's base indexer and resolved by `CollectionService` exactly like
|
||||
@@ -87,6 +89,19 @@ lunar:meilisearch:setup` re-syncs index settings, and existing documents need
|
||||
the queue worker also needs restarting after deploying changes to the indexer class —
|
||||
see `docs/lunar.md` "Gotchas".
|
||||
|
||||
**`product_count` needs the product index reindexed first.** `config/lunar/search.php`'s
|
||||
`indexers` array is typically ordered `Collection` before `Product`, so a plain
|
||||
`lunar:search:index --refresh` computes `product_count` against whatever the product
|
||||
index held *before* this run — stale if products changed too. `lunar:search:index`
|
||||
takes an explicit model list as its argument (`--ignore` restricts it to only those),
|
||||
so reindex products first, then collections, when both need a fresh `--refresh` in the
|
||||
same deploy:
|
||||
|
||||
```
|
||||
php artisan lunar:search:index "Lunar\Models\Product" --ignore --refresh
|
||||
php artisan lunar:search:index "Lunar\Models\Collection" --ignore --refresh
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## When to still use Eloquent directly
|
||||
|
||||
Reference in New Issue
Block a user