Skip to content

Commit

Permalink
Add meilisearch meta data to results
Browse files Browse the repository at this point in the history
add result meta data to the return models with `withScoutMetadata`
  • Loading branch information
tobz-nz authored Nov 15, 2023
1 parent 03c94ec commit 046442e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Engines/MeilisearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,16 @@ public function map(Builder $builder, $results, $model)

return $model->getScoutModelsByIds(
$builder, $objectIds
)->filter(function ($model) use ($objectIds) {
)->map(function ($model) use ($results, $objectIdPositions) {
$result = $results['hits'][$objectIdPositions[$model->getScoutKey()]] ?? [];
foreach ($result as $key => $value) {
if (substr($key, 0, 1) === '_') {
$model->withScoutMetadata($key, $value);
}
}

return $model;
})->filter(function ($model) use ($objectIds) {
return in_array($model->getScoutKey(), $objectIds);
})->sortBy(function ($model) use ($objectIdPositions) {
return $objectIdPositions[$model->getScoutKey()];
Expand Down

0 comments on commit 046442e

Please sign in to comment.