Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update indexers to add compatibility for Typesense #1568

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/core/src/Search/BrandIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => (int) $model->created_at->timestamp,
], $this->mapSearchableAttributes($model));
}
}
9 changes: 9 additions & 0 deletions packages/core/src/Search/CollectionIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Lunar\Search;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

class CollectionIndexer extends ScoutIndexer
{
Expand All @@ -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' => (int) $model->created_at->timestamp,
], $this->mapSearchableAttributes($model));
}
}
3 changes: 2 additions & 1 deletion packages/core/src/Search/CustomerIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => (int) $model->created_at->timestamp,
], $this->mapSearchableAttributes($model));

foreach ($metaFields as $key => $value) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/Search/OrderIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => (int) $model->created_at->timestamp,
'sub_total' => $model->sub_total->value,
'total' => $model->total->value,
'currency_code' => $model->currency_code,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Search/ScoutIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function toSearchableArray(Model $model): array
}

return array_merge([
'id' => $model->id,
'id' => (string) $model->id,
], $data);
}

Expand Down
Loading