Skip to content

Commit

Permalink
Handle sorting (Meilisearch) (#537)
Browse files Browse the repository at this point in the history
* Update MeiliSearchEngine.php

Handle sorting.

* Update MeiliSearchEngine.php

CS

* Update MeiliSearchEngine.php

CS

* formatting

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
mgralikowski and taylorotwell committed Jan 14, 2022
1 parent fa91dad commit 3c16044
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Engines/MeiliSearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public function search(Builder $builder)
return $this->performSearch($builder, array_filter([
'filters' => $this->filters($builder),
'limit' => $builder->limit,
'sort' => $this->buildSortFromOrderByClauses($builder),
]));
}

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

/**
* Get the sort array for the query.
*
* @param \Laravel\Scout\Builder $builder
* @return array
*/
protected function buildSortFromOrderByClauses(Builder $builder): array
{
return collect($builder->orders)->map(function (array $order) {
return $order['column'].':'.$order['direction'];
})->toArray();
}

/**
* Pluck and return the primary keys of the given results.
*
Expand Down

0 comments on commit 3c16044

Please sign in to comment.