forked from typesense/typesense-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSynonymSets.php
More file actions
93 lines (80 loc) · 1.94 KB
/
SynonymSets.php
File metadata and controls
93 lines (80 loc) · 1.94 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace Typesense;
use Http\Client\Exception as HttpClientException;
use Typesense\Exceptions\TypesenseClientError;
/**
* Class SynonymSets
*
* @package \Typesense
*/
class SynonymSets implements \ArrayAccess
{
public const RESOURCE_PATH = '/synonym_sets';
/**
* @var ApiCall
*/
private ApiCall $apiCall;
/**
* @var array
*/
private array $synonymSets = [];
/**
* SynonymSets constructor.
*
* @param ApiCall $apiCall
*/
public function __construct(ApiCall $apiCall)
{
$this->apiCall = $apiCall;
}
/**
* @param string $synonymSetName
* @param array $config
*
* @return array
* @throws TypesenseClientError|HttpClientException
*/
public function upsert(string $synonymSetName, array $config): array
{
return $this->apiCall->put(sprintf('%s/%s', static::RESOURCE_PATH, encodeURIComponent($synonymSetName)), $config);
}
/**
* @return array
* @throws TypesenseClientError|HttpClientException
*/
public function retrieve(): array
{
return $this->apiCall->get(static::RESOURCE_PATH, []);
}
/**
* @inheritDoc
*/
public function offsetExists($synonymSetName): bool
{
return isset($this->synonymSets[$synonymSetName]);
}
/**
* @inheritDoc
*/
public function offsetGet($synonymSetName): SynonymSet
{
if (!isset($this->synonymSets[$synonymSetName])) {
$this->synonymSets[$synonymSetName] = new SynonymSet($synonymSetName, $this->apiCall);
}
return $this->synonymSets[$synonymSetName];
}
/**
* @inheritDoc
*/
public function offsetSet($synonymSetName, $value): void
{
$this->synonymSets[$synonymSetName] = $value;
}
/**
* @inheritDoc
*/
public function offsetUnset($synonymSetName): void
{
unset($this->synonymSets[$synonymSetName]);
}
}