Skip to content

Commit

Permalink
allow custom order by
Browse files Browse the repository at this point in the history
  • Loading branch information
Ar0010r committed Jun 20, 2023
1 parent 3a109ad commit 294b678
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Infrastructure/Scout/ScoutSearchCommandBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use JeroenG\Explorer\Domain\Syntax\Compound\QueryType;
use JeroenG\Explorer\Domain\Syntax\MultiMatch;
use JeroenG\Explorer\Domain\Syntax\Sort;
use JeroenG\Explorer\Domain\Syntax\SyntaxInterface;
use JeroenG\Explorer\Domain\Syntax\Term;
use JeroenG\Explorer\Domain\Syntax\Terms;
use Laravel\Scout\Builder;
Expand All @@ -33,7 +34,7 @@ class ScoutSearchCommandBuilder implements SearchCommandInterface

private ?string $minimumShouldMatch = null;

/** @var Sort[] */
/** @var SyntaxInterface[] */
private array $sort = [];

private array $aggregations = [];
Expand Down Expand Up @@ -207,7 +208,7 @@ public function setLimit(?int $limit): void

public function setSort(array $sort): void
{
Assert::allIsInstanceOf($sort, Sort::class);
Assert::allIsInstanceOf($sort, SyntaxInterface::class);
$this->sort = $sort;
}

Expand Down Expand Up @@ -307,6 +308,8 @@ public function getOffset(): ?int
/** @return Sort[] */
private static function getSorts(Builder $builder): array
{
return array_map(static fn ($order) => new Sort($order['column'], $order['direction']), $builder->orders);
return array_map(static function($order) {
return $order instanceof SyntaxInterface ? $order : new Sort($order['column'], $order['direction']);
}, $builder->orders);
}
}

0 comments on commit 294b678

Please sign in to comment.