Skip to content

Commit 9b4bfe8

Browse files
authored
Merge pull request #146 from apisearch-io/feature/result-agg-with-metadata
Added with metadata in result agg
2 parents 099686b + 13dff0c commit 9b4bfe8

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Result/Aggregation.php

+10
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ public function getMetadata(): array
193193
return $this->metadata;
194194
}
195195

196+
/**
197+
* @param array $metadata
198+
*
199+
* @return void
200+
*/
201+
public function withMetadata(array $metadata)
202+
{
203+
$this->metadata = $metadata;
204+
}
205+
196206
/**
197207
* Get all elements.
198208
*

Tests/Result/AggregationTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,22 @@ public function testCreateFromArrayAllValues()
249249
$this->assertEquals(100, $aggregation->getTotalElements());
250250
$this->assertCount(1, $aggregation->getActiveElements());
251251
}
252+
253+
/**
254+
* @return void
255+
*/
256+
public function testWithMetadata()
257+
{
258+
$aggregation = Aggregation::createFromArray([
259+
'name' => 'agg1',
260+
'counters' => [],
261+
'application_type' => Filter::MUST_ALL,
262+
'active_elements' => ['1'],
263+
'total_elements' => 100,
264+
'metadata' => ['a' => 1, 'b' => 2],
265+
]);
266+
267+
$aggregation->withMetadata(['m']);
268+
$this->assertEquals(['m'], $aggregation->getMetadata());
269+
}
252270
}

0 commit comments

Comments
 (0)