From b042a9e500f25191f634f62bd35b9d3299ca3c96 Mon Sep 17 00:00:00 2001 From: Glenn Jacobs Date: Fri, 16 Feb 2024 13:38:22 +0000 Subject: [PATCH 1/3] Update indexers to add compatibility for Typesense --- packages/core/src/Search/BrandIndexer.php | 3 ++- packages/core/src/Search/CollectionIndexer.php | 9 +++++++++ packages/core/src/Search/CustomerIndexer.php | 3 ++- packages/core/src/Search/OrderIndexer.php | 4 ++-- packages/core/src/Search/ScoutIndexer.php | 2 +- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/core/src/Search/BrandIndexer.php b/packages/core/src/Search/BrandIndexer.php index 134261c3ec..17493b7cda 100644 --- a/packages/core/src/Search/BrandIndexer.php +++ b/packages/core/src/Search/BrandIndexer.php @@ -32,8 +32,9 @@ public function makeAllSearchableUsing(Builder $query): Builder public function toSearchableArray(Model $model): array { return array_merge([ - 'id' => $model->id, + 'id' => (string) $model->id, 'name' => $model->name, + 'created_at' => (integer) $model->created_at->timestamp, ], $this->mapSearchableAttributes($model)); } } diff --git a/packages/core/src/Search/CollectionIndexer.php b/packages/core/src/Search/CollectionIndexer.php index 665250ddef..2ec4dfea6b 100644 --- a/packages/core/src/Search/CollectionIndexer.php +++ b/packages/core/src/Search/CollectionIndexer.php @@ -3,6 +3,7 @@ namespace Lunar\Search; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Model; class CollectionIndexer extends ScoutIndexer { @@ -27,4 +28,12 @@ public function makeAllSearchableUsing(Builder $query): Builder { return $query; } + + public function toSearchableArray(Model $model): array + { + return array_merge([ + 'id' => (string) $model->id, + 'created_at' => (integer) $model->created_at->timestamp, + ], $this->mapSearchableAttributes($model)); + } } diff --git a/packages/core/src/Search/CustomerIndexer.php b/packages/core/src/Search/CustomerIndexer.php index 8f205a4dc3..05e9164cea 100644 --- a/packages/core/src/Search/CustomerIndexer.php +++ b/packages/core/src/Search/CustomerIndexer.php @@ -38,11 +38,12 @@ public function toSearchableArray(Model $model): array $metaFields = (array) $model->meta; $data = array_merge([ - 'id' => $model->id, + 'id' => (string) $model->id, 'name' => $model->fullName, 'company_name' => $model->company_name, 'vat_no' => $model->vat_no, 'account_ref' => $model->account_ref, + 'created_at' => (integer) $model->created_at->timestamp, ], $this->mapSearchableAttributes($model)); foreach ($metaFields as $key => $value) { diff --git a/packages/core/src/Search/OrderIndexer.php b/packages/core/src/Search/OrderIndexer.php index 43ceba4ff5..9669998206 100644 --- a/packages/core/src/Search/OrderIndexer.php +++ b/packages/core/src/Search/OrderIndexer.php @@ -46,13 +46,13 @@ public function makeAllSearchableUsing(Builder $query): Builder public function toSearchableArray(Model $model): array { $data = [ - 'id' => $model->id, + 'id' => (string) $model->id, 'channel' => $model->channel->name, 'reference' => $model->reference, 'customer_reference' => $model->customer_reference, 'status' => $model->status, 'placed_at' => optional($model->placed_at)->timestamp, - 'created_at' => $model->created_at->timestamp, + 'created_at' => (integer) $model->created_at->timestamp, 'sub_total' => $model->sub_total->value, 'total' => $model->total->value, 'currency_code' => $model->currency_code, diff --git a/packages/core/src/Search/ScoutIndexer.php b/packages/core/src/Search/ScoutIndexer.php index 188f95fba8..89decd3af2 100644 --- a/packages/core/src/Search/ScoutIndexer.php +++ b/packages/core/src/Search/ScoutIndexer.php @@ -61,7 +61,7 @@ public function toSearchableArray(Model $model): array } return array_merge([ - 'id' => $model->id, + 'id' => (string) $model->id, ], $data); } From 93820c1b2b16b07aea5b3ca0b45c3de2a13452ec Mon Sep 17 00:00:00 2001 From: glennjacobs Date: Fri, 16 Feb 2024 13:40:41 +0000 Subject: [PATCH 2/3] chore: fix code style --- packages/core/src/Search/BrandIndexer.php | 2 +- packages/core/src/Search/CollectionIndexer.php | 2 +- packages/core/src/Search/CustomerIndexer.php | 2 +- packages/core/src/Search/OrderIndexer.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/src/Search/BrandIndexer.php b/packages/core/src/Search/BrandIndexer.php index 17493b7cda..b51d38d41a 100644 --- a/packages/core/src/Search/BrandIndexer.php +++ b/packages/core/src/Search/BrandIndexer.php @@ -34,7 +34,7 @@ public function toSearchableArray(Model $model): array return array_merge([ 'id' => (string) $model->id, 'name' => $model->name, - 'created_at' => (integer) $model->created_at->timestamp, + 'created_at' => (int) $model->created_at->timestamp, ], $this->mapSearchableAttributes($model)); } } diff --git a/packages/core/src/Search/CollectionIndexer.php b/packages/core/src/Search/CollectionIndexer.php index 2ec4dfea6b..d9c570b81f 100644 --- a/packages/core/src/Search/CollectionIndexer.php +++ b/packages/core/src/Search/CollectionIndexer.php @@ -33,7 +33,7 @@ public function toSearchableArray(Model $model): array { return array_merge([ 'id' => (string) $model->id, - 'created_at' => (integer) $model->created_at->timestamp, + 'created_at' => (int) $model->created_at->timestamp, ], $this->mapSearchableAttributes($model)); } } diff --git a/packages/core/src/Search/CustomerIndexer.php b/packages/core/src/Search/CustomerIndexer.php index 05e9164cea..8dffa3e7ad 100644 --- a/packages/core/src/Search/CustomerIndexer.php +++ b/packages/core/src/Search/CustomerIndexer.php @@ -43,7 +43,7 @@ public function toSearchableArray(Model $model): array 'company_name' => $model->company_name, 'vat_no' => $model->vat_no, 'account_ref' => $model->account_ref, - 'created_at' => (integer) $model->created_at->timestamp, + 'created_at' => (int) $model->created_at->timestamp, ], $this->mapSearchableAttributes($model)); foreach ($metaFields as $key => $value) { diff --git a/packages/core/src/Search/OrderIndexer.php b/packages/core/src/Search/OrderIndexer.php index 9669998206..758be98c38 100644 --- a/packages/core/src/Search/OrderIndexer.php +++ b/packages/core/src/Search/OrderIndexer.php @@ -52,7 +52,7 @@ public function toSearchableArray(Model $model): array 'customer_reference' => $model->customer_reference, 'status' => $model->status, 'placed_at' => optional($model->placed_at)->timestamp, - 'created_at' => (integer) $model->created_at->timestamp, + 'created_at' => (int) $model->created_at->timestamp, 'sub_total' => $model->sub_total->value, 'total' => $model->total->value, 'currency_code' => $model->currency_code, From 8088a972a129ac4059c3d8f30ca068f3d759e669 Mon Sep 17 00:00:00 2001 From: Glenn Jacobs Date: Fri, 16 Feb 2024 13:54:41 +0000 Subject: [PATCH 3/3] Update ScoutIndexerTest.php --- tests/core/Unit/Search/ScoutIndexerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/Unit/Search/ScoutIndexerTest.php b/tests/core/Unit/Search/ScoutIndexerTest.php index d0ed350c3f..e2056c8ad2 100644 --- a/tests/core/Unit/Search/ScoutIndexerTest.php +++ b/tests/core/Unit/Search/ScoutIndexerTest.php @@ -39,7 +39,7 @@ $data = app(ScoutIndexer::class)->toSearchableArray($product); expect($data)->toBe([ - 'id' => $product->id, + 'id' => (string) $product->id, ]); });