Skip to content

Commit 2de4e30

Browse files
authored
Merge pull request #117 from apisearch-io/feature/index-with-metadata-value
Added withMetadataValue for complementing across layers
2 parents e39f99a + 262c38e commit 2de4e30

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Model/Index.php

+13
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,19 @@ public function getMetadataValue(string $key)
221221
return $this->metadata[$key] ?? null;
222222
}
223223

224+
/**
225+
* With metadata value. Useful for metadata completion across layers.
226+
*
227+
* @param string $key
228+
* @param mixed $value
229+
*/
230+
public function withMetadataValue(
231+
string $key,
232+
$value
233+
) {
234+
$this->metadata[$key] = $value;
235+
}
236+
224237
/**
225238
* To array.
226239
*

Tests/Model/IndexTest.php

+24
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,28 @@ public function testCreateValidIndex(): void
121121
$this->assertEquals([], $index3->getMetadata());
122122
$this->assertEquals([], $index3->getFields());
123123
}
124+
125+
/**
126+
* Test with metadata value.
127+
*/
128+
public function testWithMetadataValue()
129+
{
130+
$index = Index::createFromArray([
131+
'uuid' => [
132+
'id' => 'testId',
133+
],
134+
'app_id' => [
135+
'id' => 'testAppId',
136+
],
137+
'is_ok' => true,
138+
'doc_count' => 10,
139+
'size' => '1kb',
140+
]);
141+
142+
$this->assertNull($index->getMetadataValue('key1'));
143+
$index->withMetadataValue('key1', 'val1');
144+
$this->assertEquals('val1', $index->getMetadataValue('key1'));
145+
$index = Index::createFromArray($index->toArray());
146+
$this->assertEquals('val1', $index->getMetadataValue('key1'));
147+
}
124148
}

0 commit comments

Comments
 (0)