Skip to content

Commit

Permalink
feat: add IndexSchema2xDocument::setMetaText()
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed Mar 12, 2024
1 parent 6c2a775 commit cc386ba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Service/Indexer/IndexSchema2xDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,32 @@ class IndexSchema2xDocument extends Document implements IndexDocument
*/
private array $metaString = [];

/**
* @var array<string,string|string[]>
*/
private array $metaText = [];

/**
* @var array<string,bool>
*/
private array $metaBool = [];

/**
* @param string $name
* @param string|string[] $value
* @return void
*/
public function setMetaString(string $name, string|array $value): void
{
$this->metaString[$name] = $value;
}

/**
* @param string|string[] $value
*/
public function setMetaText(string $name, string|array $value): void
{
$this->metaText[$name] = $value;
}

public function setMetaBool(string $name, bool $value): void
{
$this->metaBool[$name] = $value;
Expand Down Expand Up @@ -175,6 +186,7 @@ static function ($value, $key) {

if (
$key === 'metaString' ||
$key === 'metaText' ||
$key === 'metaBool'
) {
return false;
Expand All @@ -187,6 +199,10 @@ static function ($value, $key) {
$fields['sp_meta_string_' . $key] = $value;
}

foreach ($this->metaText as $key => $value) {
$fields['sp_meta_text_' . $key] = $value;
}

foreach ($this->metaBool as $key => $value) {
$fields['sp_meta_bool_' . $key] = $value;
}
Expand Down
12 changes: 12 additions & 0 deletions test/Service/Indexer/IndexSchema2xDocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ public function testSetMetaString(): void
);
}

public function testSetMetaText(): void
{
$doc = new IndexSchema2xDocument();
$doc->setMetaText('myname', 'myvalue');

$this->assertEquals(
['sp_meta_text_myname' => 'myvalue'],
$doc->getFields(),
'unexpected meta fields'
);
}

public function testSetMetaBool(): void
{
$doc = new IndexSchema2xDocument();
Expand Down

0 comments on commit cc386ba

Please sign in to comment.