-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateSynonymRuleAdaptor.php
More file actions
49 lines (38 loc) · 1.59 KB
/
UpdateSynonymRuleAdaptor.php
File metadata and controls
49 lines (38 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace SilverStripe\ForagerBifrost\Adaptors\Requests;
use Elastic\EnterpriseSearch\Client;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forager\Interfaces\Requests\UpdateSynonymRuleAdaptor as PatchSynonymRuleAdaptorInterface;
use SilverStripe\Forager\Service\Query\SynonymRule as SynonymRuleQuery;
use SilverStripe\Forager\Service\Results\SynonymRule as SynonymRuleResult;
use SilverStripe\ForagerBifrost\Processors\SynonymRuleProcessor;
use SilverStripe\ForagerBifrost\Service\Requests\UpdateSynonymRule;
class UpdateSynonymRuleAdaptor implements PatchSynonymRuleAdaptorInterface
{
private ?Client $client = null;
private static array $dependencies = [
'client' => '%$' . Client::class . '.managementClient',
];
public function setClient(?Client $client): void
{
$this->client = $client;
}
public function process(
int|string $synonymCollectionId,
int|string $synonymRuleId,
SynonymRuleQuery $synonymRule
): SynonymRuleResult {
$request = Injector::inst()->create(
UpdateSynonymRule::class,
$synonymCollectionId,
$synonymRuleId,
$synonymRule
);
// Should either be successful or throw an exception, which we'll let fly
$body = $this->client->appSearch()->createSynonymSet($request)->asString();
$body = json_decode($body, true);
$synonymRuleResult = SynonymRuleResult::create($body['id']);
SynonymRuleProcessor::applyStringToResult($synonymRuleResult, $body['synonyms']);
return $synonymRuleResult;
}
}