Skip to content

Commit 3c16044

Browse files
Handle sorting (Meilisearch) (#537)
* Update MeiliSearchEngine.php Handle sorting. * Update MeiliSearchEngine.php CS * Update MeiliSearchEngine.php CS * formatting Co-authored-by: Taylor Otwell <[email protected]>
1 parent fa91dad commit 3c16044

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Engines/MeiliSearchEngine.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public function search(Builder $builder)
101101
return $this->performSearch($builder, array_filter([
102102
'filters' => $this->filters($builder),
103103
'limit' => $builder->limit,
104+
'sort' => $this->buildSortFromOrderByClauses($builder),
104105
]));
105106
}
106107

@@ -185,6 +186,19 @@ protected function filters(Builder $builder)
185186
return $filters->values()->implode(' AND ');
186187
}
187188

189+
/**
190+
* Get the sort array for the query.
191+
*
192+
* @param \Laravel\Scout\Builder $builder
193+
* @return array
194+
*/
195+
protected function buildSortFromOrderByClauses(Builder $builder): array
196+
{
197+
return collect($builder->orders)->map(function (array $order) {
198+
return $order['column'].':'.$order['direction'];
199+
})->toArray();
200+
}
201+
188202
/**
189203
* Pluck and return the primary keys of the given results.
190204
*

0 commit comments

Comments
 (0)