Skip to content

Commit

Permalink
Retain order from extension onfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Richter committed Dec 10, 2024
1 parent 4ab1cae commit 50f3938
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Classes/Services/ElasticSearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Elastic\Elasticsearch\Client;
use Elastic\Elasticsearch\Response\Elasticsearch;
use Http\Promise\Promise;
use Illuminate\Support\Collection;
use Slub\LisztCommon\Common\Collection;
use Slub\LisztCommon\Common\ElasticClientBuilder;
use Slub\LisztCommon\Common\QueryParamsBuilder;
use Slub\LisztCommon\Interfaces\ElasticSearchServiceInterface;
Expand Down Expand Up @@ -47,8 +47,22 @@ public function search(array $searchParams, array $settings): Collection
$this->params = QueryParamsBuilder::createQueryParamsBuilder($searchParams, $settings)->getQueryParams();

// ToDo: handle exceptions!
$response = $this->client->search($this->params);
return new Collection($response->asArray());
$response = $this->client->search($this->params)->asArray();
$aggs = $response['aggregations'];

$sortedAggsFromSettings = Collection::wrap($this->params)->
recursive()->
get('body')->
// to retain their order, we retrieve the aggs from the params
get('aggs')->
// retrieve their keys
keys()->
// and get the respective part from the response aggregations
mapWithKeys(function ($key) use ($aggs) { return [ $key => $aggs[$key] ]; })->
all();
$response['aggregations'] = $sortedAggsFromSettings;

return new Collection($response);
}

public function count(array $searchParams, array $settings): int
Expand Down

0 comments on commit 50f3938

Please sign in to comment.