Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Driver/OpenSearch/OpenSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ public function search(Search $search): SearchResult
}
}

if (isset($response->aggregations) && is_object($response->aggregations)) {
$result->setAggregations($response->aggregations);
}

foreach ($response->hits->hits as $resultDocument) {
/** @var ModelInterface $model */
$model = new $modelClassName();
Expand Down
22 changes: 22 additions & 0 deletions src/Search/SearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SearchResult extends ModelCollection
protected ?int $searchTime = null;
protected ?int $totalCount = null;
protected ?CountRelation $totalCountRelation = null;
protected ?object $aggregations = null;

/**
* @return int|null
Expand Down Expand Up @@ -70,4 +71,25 @@ public function setTotalCountRelation(?CountRelation $totalCountRelation): stati
$this->totalCountRelation = $totalCountRelation;
return $this;
}

/**
* Aggregations returned by OpenSearch, if any.
* The structure of this object depends on the aggregations defined in the search query.
*
* @return object|null
*/
public function getAggregations(): ?object
{
return $this->aggregations;
}

/**
* @param object|null $aggregations
* @return $this
*/
public function setAggregations(?object $aggregations): static
{
$this->aggregations = $aggregations;
return $this;
}
}
Loading