Skip to content

Commit 9d8a2ac

Browse files
authored
Merge pull request #49 from KurtThiemann/opensearch-aggregations
Add basic aggregation support to OpenSearch
2 parents 56733ed + f3c22c8 commit 9d8a2ac

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/Driver/OpenSearch/OpenSearch.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ public function search(Search $search): SearchResult
233233
}
234234
}
235235

236+
if (isset($response->aggregations) && is_object($response->aggregations)) {
237+
$result->setAggregations($response->aggregations);
238+
}
239+
236240
foreach ($response->hits->hits as $resultDocument) {
237241
/** @var ModelInterface $model */
238242
$model = new $modelClassName();

src/Search/SearchResult.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class SearchResult extends ModelCollection
1616
protected ?int $searchTime = null;
1717
protected ?int $totalCount = null;
1818
protected ?CountRelation $totalCountRelation = null;
19+
protected ?object $aggregations = null;
1920

2021
/**
2122
* @return int|null
@@ -70,4 +71,25 @@ public function setTotalCountRelation(?CountRelation $totalCountRelation): stati
7071
$this->totalCountRelation = $totalCountRelation;
7172
return $this;
7273
}
74+
75+
/**
76+
* Aggregations returned by OpenSearch, if any.
77+
* The structure of this object depends on the aggregations defined in the search query.
78+
*
79+
* @return object|null
80+
*/
81+
public function getAggregations(): ?object
82+
{
83+
return $this->aggregations;
84+
}
85+
86+
/**
87+
* @param object|null $aggregations
88+
* @return $this
89+
*/
90+
public function setAggregations(?object $aggregations): static
91+
{
92+
$this->aggregations = $aggregations;
93+
return $this;
94+
}
7395
}

0 commit comments

Comments
 (0)