/
SearchClient.php
2956 lines (2652 loc) 路 128 KB
/
SearchClient.php
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
namespace Algolia\AlgoliaSearch\Api;
use Algolia\AlgoliaSearch\Algolia;
use Algolia\AlgoliaSearch\Configuration\SearchConfig;
use Algolia\AlgoliaSearch\Exceptions\ExceededRetriesException;
use Algolia\AlgoliaSearch\Exceptions\ValidUntilNotFoundException;
use Algolia\AlgoliaSearch\Iterators\ObjectIterator;
use Algolia\AlgoliaSearch\Iterators\RuleIterator;
use Algolia\AlgoliaSearch\Iterators\SynonymIterator;
use Algolia\AlgoliaSearch\ObjectSerializer;
use Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper;
use Algolia\AlgoliaSearch\RetryStrategy\ApiWrapperInterface;
use Algolia\AlgoliaSearch\RetryStrategy\ClusterHosts;
use Algolia\AlgoliaSearch\Support\Helpers;
/**
* SearchClient Class Doc Comment.
*
* @category Class
*/
class SearchClient
{
public const VERSION = '4.0.0-beta.1';
/**
* @var ApiWrapperInterface
*/
protected $api;
/**
* @var SearchConfig
*/
protected $config;
public function __construct(ApiWrapperInterface $apiWrapper, SearchConfig $config)
{
$this->config = $config;
$this->api = $apiWrapper;
}
/**
* Instantiate the client with basic credentials.
*
* @param string $appId Application ID
* @param string $apiKey Algolia API Key
*/
public static function create($appId = null, $apiKey = null)
{
return static::createWithConfig(SearchConfig::create($appId, $apiKey));
}
/**
* Instantiate the client with configuration.
*
* @param SearchConfig $config Configuration
*/
public static function createWithConfig(SearchConfig $config)
{
$config = clone $config;
$apiWrapper = new ApiWrapper(
Algolia::getHttpClient(),
$config,
self::getClusterHosts($config)
);
return new static($apiWrapper, $config);
}
/**
* Gets the cluster hosts depending on the config.
*
* @return ClusterHosts
*/
public static function getClusterHosts(SearchConfig $config)
{
$cacheKey = sprintf('%s-clusterHosts-%s', __CLASS__, $config->getAppId());
if ($hosts = $config->getHosts()) {
// If a list of hosts was passed, we ignore the cache
$clusterHosts = ClusterHosts::create($hosts);
} elseif (false === ($clusterHosts = ClusterHosts::createFromCache($cacheKey))) {
// We'll try to restore the ClusterHost from cache, if we cannot
// we create a new instance and set the cache key
$clusterHosts = ClusterHosts::createFromAppId($config->getAppId())
->setCacheKey($cacheKey)
;
}
return $clusterHosts;
}
/**
* @return SearchConfig
*/
public function getClientConfig()
{
return $this->config;
}
/**
* Creates a new API key with specific permissions and restrictions.
*
* Required API Key ACLs:
* - admin
*
* @param array $apiKey apiKey (required)
* - $apiKey['acl'] => (array) Permissions that determine the type of API requests this key can make. The required ACL is listed in each endpoint's reference. For more information, see [access control list](https://www.algolia.com/doc/guides/security/api-keys/#access-control-list-acl). (required)
* - $apiKey['description'] => (string) Description of an API key to help you identify this API key.
* - $apiKey['indexes'] => (array) Index names or patterns that this API key can access. By default, an API key can access all indices in the same application. You can use leading and trailing wildcard characters (`*`): - `dev_*` matches all indices starting with \"dev_\". - `*_dev` matches all indices ending with \"_dev\". - `*_products_*` matches all indices containing \"_products_\".
* - $apiKey['maxHitsPerQuery'] => (int) Maximum number of results this API key can retrieve in one query. By default, there's no limit.
* - $apiKey['maxQueriesPerIPPerHour'] => (int) Maximum number of API requests allowed per IP address or [user token](https://www.algolia.com/doc/guides/sending-events/concepts/usertoken/) per hour. If this limit is reached, the API returns an error with status code `429`. By default, there's no limit.
* - $apiKey['queryParameters'] => (string) Query parameters to add when making API requests with this API key. To restrict this API key to specific IP addresses, add the `restrictSources` parameter. You can only add a single source, but you can provide a range of IP addresses. Creating an API key fails if the request is made from an IP address that's outside the restricted range.
* - $apiKey['referers'] => (array) Allowed HTTP referrers for this API key. By default, all referrers are allowed. You can use leading and trailing wildcard characters (`*`): - `https://algolia.com/_*` allows all referrers starting with \"https://algolia.com/\" - `*.algolia.com` allows all referrers ending with \".algolia.com\" - `*algolia.com*` allows all referrers in the domain \"algolia.com\". Like all HTTP headers, referrers can be spoofed. Don't rely on them to secure your data. For more information, see [HTTP referrer restrictions](https://www.algolia.com/doc/guides/security/security-best-practices/#http-referrers-restrictions).
* - $apiKey['validity'] => (int) Duration (in seconds) after which the API key expires. By default, API keys don't expire.
*
* @see \Algolia\AlgoliaSearch\Model\Search\ApiKey
*
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return \Algolia\AlgoliaSearch\Model\Search\AddApiKeyResponse|array<string, mixed>
*/
public function addApiKey($apiKey, $requestOptions = [])
{
// verify the required parameter 'apiKey' is set
if (!isset($apiKey)) {
throw new \InvalidArgumentException(
'Parameter `apiKey` is required when calling `addApiKey`.'
);
}
$resourcePath = '/1/keys';
$queryParameters = [];
$headers = [];
$httpBody = $apiKey;
return $this->sendRequest('POST', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* If a record with the specified object ID exists, the existing record is replaced. Otherwise, a new record is added to the index. To update _some_ attributes of an existing record, use the [`partial` operation](#tag/Records/operation/partialUpdateObject) instead. To add, update, or replace multiple records, use the [`batch` operation](#tag/Records/operation/batch).
*
* Required API Key ACLs:
* - addObject
*
* @param string $indexName Name of the index on which to perform the operation. (required)
* @param string $objectID Unique record identifier. (required)
* @param array $body The record, a schemaless object with attributes that are useful in the context of search and discovery. (required)
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return \Algolia\AlgoliaSearch\Model\Search\UpdatedAtWithObjectIdResponse|array<string, mixed>
*/
public function addOrUpdateObject($indexName, $objectID, $body, $requestOptions = [])
{
// verify the required parameter 'indexName' is set
if (!isset($indexName)) {
throw new \InvalidArgumentException(
'Parameter `indexName` is required when calling `addOrUpdateObject`.'
);
}
// verify the required parameter 'objectID' is set
if (!isset($objectID)) {
throw new \InvalidArgumentException(
'Parameter `objectID` is required when calling `addOrUpdateObject`.'
);
}
// verify the required parameter 'body' is set
if (!isset($body)) {
throw new \InvalidArgumentException(
'Parameter `body` is required when calling `addOrUpdateObject`.'
);
}
$resourcePath = '/1/indexes/{indexName}/{objectID}';
$queryParameters = [];
$headers = [];
$httpBody = $body;
// path params
if (null !== $indexName) {
$resourcePath = str_replace(
'{indexName}',
ObjectSerializer::toPathValue($indexName),
$resourcePath
);
}
// path params
if (null !== $objectID) {
$resourcePath = str_replace(
'{objectID}',
ObjectSerializer::toPathValue($objectID),
$resourcePath
);
}
return $this->sendRequest('PUT', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* Adds a source to the list of allowed sources.
*
* Required API Key ACLs:
* - admin
*
* @param array $source Source to add. (required)
* - $source['source'] => (string) IP address range of the source. (required)
* - $source['description'] => (string) Source description.
*
* @see \Algolia\AlgoliaSearch\Model\Search\Source
*
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return \Algolia\AlgoliaSearch\Model\Search\CreatedAtResponse|array<string, mixed>
*/
public function appendSource($source, $requestOptions = [])
{
// verify the required parameter 'source' is set
if (!isset($source)) {
throw new \InvalidArgumentException(
'Parameter `source` is required when calling `appendSource`.'
);
}
$resourcePath = '/1/security/sources/append';
$queryParameters = [];
$headers = [];
$httpBody = $source;
return $this->sendRequest('POST', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* Assigns or moves a user ID to a cluster. The time it takes to move a user is proportional to the amount of data linked to the user ID.
*
* Required API Key ACLs:
* - admin
*
* @param string $xAlgoliaUserID Unique identifier of the user who makes the search request. (required)
* @param array $assignUserIdParams assignUserIdParams (required)
* - $assignUserIdParams['cluster'] => (string) Cluster name. (required)
*
* @see \Algolia\AlgoliaSearch\Model\Search\AssignUserIdParams
*
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return \Algolia\AlgoliaSearch\Model\Search\CreatedAtResponse|array<string, mixed>
*/
public function assignUserId($xAlgoliaUserID, $assignUserIdParams, $requestOptions = [])
{
// verify the required parameter 'xAlgoliaUserID' is set
if (!isset($xAlgoliaUserID)) {
throw new \InvalidArgumentException(
'Parameter `xAlgoliaUserID` is required when calling `assignUserId`.'
);
}
if (!preg_match('/^[a-zA-Z0-9 \\-*.]+$/', $xAlgoliaUserID)) {
throw new \InvalidArgumentException('invalid value for "xAlgoliaUserID" when calling SearchClient.assignUserId, must conform to the pattern /^[a-zA-Z0-9 \\-*.]+$/.');
}
// verify the required parameter 'assignUserIdParams' is set
if (!isset($assignUserIdParams)) {
throw new \InvalidArgumentException(
'Parameter `assignUserIdParams` is required when calling `assignUserId`.'
);
}
$resourcePath = '/1/clusters/mapping';
$queryParameters = [];
$headers = [];
$httpBody = $assignUserIdParams;
$headers['X-Algolia-User-ID'] = $xAlgoliaUserID;
return $this->sendRequest('POST', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* Adds, updates, or deletes records in one index with a single API request. Batching index updates reduces latency and increases data integrity. - Actions are applied in the order they're specified. - Actions are equivalent to the individual API requests of the same name.
*
* @param string $indexName Name of the index on which to perform the operation. (required)
* @param array $batchWriteParams batchWriteParams (required)
* - $batchWriteParams['requests'] => (array) (required)
*
* @see \Algolia\AlgoliaSearch\Model\Search\BatchWriteParams
*
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return \Algolia\AlgoliaSearch\Model\Search\BatchResponse|array<string, mixed>
*/
public function batch($indexName, $batchWriteParams, $requestOptions = [])
{
// verify the required parameter 'indexName' is set
if (!isset($indexName)) {
throw new \InvalidArgumentException(
'Parameter `indexName` is required when calling `batch`.'
);
}
// verify the required parameter 'batchWriteParams' is set
if (!isset($batchWriteParams)) {
throw new \InvalidArgumentException(
'Parameter `batchWriteParams` is required when calling `batch`.'
);
}
$resourcePath = '/1/indexes/{indexName}/batch';
$queryParameters = [];
$headers = [];
$httpBody = $batchWriteParams;
// path params
if (null !== $indexName) {
$resourcePath = str_replace(
'{indexName}',
ObjectSerializer::toPathValue($indexName),
$resourcePath
);
}
return $this->sendRequest('POST', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* Assigns multiple user IDs to a cluster. **You can't move users with this operation**.
*
* Required API Key ACLs:
* - admin
*
* @param string $xAlgoliaUserID Unique identifier of the user who makes the search request. (required)
* @param array $batchAssignUserIdsParams batchAssignUserIdsParams (required)
* - $batchAssignUserIdsParams['cluster'] => (string) Cluster name. (required)
* - $batchAssignUserIdsParams['users'] => (array) User IDs to assign. (required)
*
* @see \Algolia\AlgoliaSearch\Model\Search\BatchAssignUserIdsParams
*
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return \Algolia\AlgoliaSearch\Model\Search\CreatedAtResponse|array<string, mixed>
*/
public function batchAssignUserIds($xAlgoliaUserID, $batchAssignUserIdsParams, $requestOptions = [])
{
// verify the required parameter 'xAlgoliaUserID' is set
if (!isset($xAlgoliaUserID)) {
throw new \InvalidArgumentException(
'Parameter `xAlgoliaUserID` is required when calling `batchAssignUserIds`.'
);
}
if (!preg_match('/^[a-zA-Z0-9 \\-*.]+$/', $xAlgoliaUserID)) {
throw new \InvalidArgumentException('invalid value for "xAlgoliaUserID" when calling SearchClient.batchAssignUserIds, must conform to the pattern /^[a-zA-Z0-9 \\-*.]+$/.');
}
// verify the required parameter 'batchAssignUserIdsParams' is set
if (!isset($batchAssignUserIdsParams)) {
throw new \InvalidArgumentException(
'Parameter `batchAssignUserIdsParams` is required when calling `batchAssignUserIds`.'
);
}
$resourcePath = '/1/clusters/mapping/batch';
$queryParameters = [];
$headers = [];
$httpBody = $batchAssignUserIdsParams;
$headers['X-Algolia-User-ID'] = $xAlgoliaUserID;
return $this->sendRequest('POST', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* Adds or deletes multiple entries from your plurals, segmentation, or stop word dictionaries.
*
* Required API Key ACLs:
* - editSettings
*
* @param array $dictionaryName Dictionary type in which to search. (required)
* @param array $batchDictionaryEntriesParams batchDictionaryEntriesParams (required)
* - $batchDictionaryEntriesParams['clearExistingDictionaryEntries'] => (bool) Whether to replace all custom entries in the dictionary with the ones sent with this request.
* - $batchDictionaryEntriesParams['requests'] => (array) List of additions and deletions to your dictionaries. (required)
*
* @see \Algolia\AlgoliaSearch\Model\Search\BatchDictionaryEntriesParams
*
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return \Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse|array<string, mixed>
*/
public function batchDictionaryEntries($dictionaryName, $batchDictionaryEntriesParams, $requestOptions = [])
{
// verify the required parameter 'dictionaryName' is set
if (!isset($dictionaryName)) {
throw new \InvalidArgumentException(
'Parameter `dictionaryName` is required when calling `batchDictionaryEntries`.'
);
}
// verify the required parameter 'batchDictionaryEntriesParams' is set
if (!isset($batchDictionaryEntriesParams)) {
throw new \InvalidArgumentException(
'Parameter `batchDictionaryEntriesParams` is required when calling `batchDictionaryEntries`.'
);
}
$resourcePath = '/1/dictionaries/{dictionaryName}/batch';
$queryParameters = [];
$headers = [];
$httpBody = $batchDictionaryEntriesParams;
// path params
if (null !== $dictionaryName) {
$resourcePath = str_replace(
'{dictionaryName}',
ObjectSerializer::toPathValue($dictionaryName),
$resourcePath
);
}
return $this->sendRequest('POST', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* Retrieves records from an index, up to 1,000 per request. While searching retrieves _hits_ (records augmented with attributes for highlighting and ranking details), browsing _just_ returns matching records. This can be useful if you want to export your indices. - The Analytics API doesn't collect data when using `browse`. - Records are ranked by attributes and custom ranking. - Deduplication (`distinct`) is turned off. - There's no ranking for: typo-tolerance, number of matched words, proximity, geo distance.
*
* Required API Key ACLs:
* - browse
*
* @param string $indexName Name of the index on which to perform the operation. (required)
* @param array $browseParams browseParams (optional)
*
* @see \Algolia\AlgoliaSearch\Model\Search\BrowseParams
*
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return \Algolia\AlgoliaSearch\Model\Search\BrowseResponse|array<string, mixed>
*/
public function browse($indexName, $browseParams = null, $requestOptions = [])
{
// verify the required parameter 'indexName' is set
if (!isset($indexName)) {
throw new \InvalidArgumentException(
'Parameter `indexName` is required when calling `browse`.'
);
}
$resourcePath = '/1/indexes/{indexName}/browse';
$queryParameters = [];
$headers = [];
$httpBody = isset($browseParams) ? $browseParams : [];
// path params
if (null !== $indexName) {
$resourcePath = str_replace(
'{indexName}',
ObjectSerializer::toPathValue($indexName),
$resourcePath
);
}
return $this->sendRequest('POST', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* Deletes only the records from an index while keeping settings, synonyms, and rules.
*
* Required API Key ACLs:
* - deleteIndex
*
* @param string $indexName Name of the index on which to perform the operation. (required)
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return \Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse|array<string, mixed>
*/
public function clearObjects($indexName, $requestOptions = [])
{
// verify the required parameter 'indexName' is set
if (!isset($indexName)) {
throw new \InvalidArgumentException(
'Parameter `indexName` is required when calling `clearObjects`.'
);
}
$resourcePath = '/1/indexes/{indexName}/clear';
$queryParameters = [];
$headers = [];
$httpBody = null;
// path params
if (null !== $indexName) {
$resourcePath = str_replace(
'{indexName}',
ObjectSerializer::toPathValue($indexName),
$resourcePath
);
}
return $this->sendRequest('POST', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* Deletes all rules from the index.
*
* Required API Key ACLs:
* - editSettings
*
* @param string $indexName Name of the index on which to perform the operation. (required)
* @param bool $forwardToReplicas Whether changes are applied to replica indices. (optional)
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return \Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse|array<string, mixed>
*/
public function clearRules($indexName, $forwardToReplicas = null, $requestOptions = [])
{
// verify the required parameter 'indexName' is set
if (!isset($indexName)) {
throw new \InvalidArgumentException(
'Parameter `indexName` is required when calling `clearRules`.'
);
}
$resourcePath = '/1/indexes/{indexName}/rules/clear';
$queryParameters = [];
$headers = [];
$httpBody = null;
if (null !== $forwardToReplicas) {
$queryParameters['forwardToReplicas'] = $forwardToReplicas;
}
// path params
if (null !== $indexName) {
$resourcePath = str_replace(
'{indexName}',
ObjectSerializer::toPathValue($indexName),
$resourcePath
);
}
return $this->sendRequest('POST', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* Deletes all synonyms from the index.
*
* Required API Key ACLs:
* - editSettings
*
* @param string $indexName Name of the index on which to perform the operation. (required)
* @param bool $forwardToReplicas Whether changes are applied to replica indices. (optional)
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return \Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse|array<string, mixed>
*/
public function clearSynonyms($indexName, $forwardToReplicas = null, $requestOptions = [])
{
// verify the required parameter 'indexName' is set
if (!isset($indexName)) {
throw new \InvalidArgumentException(
'Parameter `indexName` is required when calling `clearSynonyms`.'
);
}
$resourcePath = '/1/indexes/{indexName}/synonyms/clear';
$queryParameters = [];
$headers = [];
$httpBody = null;
if (null !== $forwardToReplicas) {
$queryParameters['forwardToReplicas'] = $forwardToReplicas;
}
// path params
if (null !== $indexName) {
$resourcePath = str_replace(
'{indexName}',
ObjectSerializer::toPathValue($indexName),
$resourcePath
);
}
return $this->sendRequest('POST', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* This method allow you to send requests to the Algolia REST API.
*
* @param string $path Path of the endpoint, anything after \"/1\" must be specified. (required)
* @param array $parameters Query parameters to apply to the current query. (optional)
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return array<string, mixed>|object
*/
public function customDelete($path, $parameters = null, $requestOptions = [])
{
// verify the required parameter 'path' is set
if (!isset($path)) {
throw new \InvalidArgumentException(
'Parameter `path` is required when calling `customDelete`.'
);
}
$resourcePath = '/{path}';
$queryParameters = [];
$headers = [];
$httpBody = null;
if (null !== $parameters) {
$queryParameters = $parameters;
}
// path params
if (null !== $path) {
$resourcePath = str_replace(
'{path}',
$path,
$resourcePath
);
}
return $this->sendRequest('DELETE', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* This method allow you to send requests to the Algolia REST API.
*
* @param string $path Path of the endpoint, anything after \"/1\" must be specified. (required)
* @param array $parameters Query parameters to apply to the current query. (optional)
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return array<string, mixed>|object
*/
public function customGet($path, $parameters = null, $requestOptions = [])
{
// verify the required parameter 'path' is set
if (!isset($path)) {
throw new \InvalidArgumentException(
'Parameter `path` is required when calling `customGet`.'
);
}
$resourcePath = '/{path}';
$queryParameters = [];
$headers = [];
$httpBody = null;
if (null !== $parameters) {
$queryParameters = $parameters;
}
// path params
if (null !== $path) {
$resourcePath = str_replace(
'{path}',
$path,
$resourcePath
);
}
return $this->sendRequest('GET', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* This method allow you to send requests to the Algolia REST API.
*
* @param string $path Path of the endpoint, anything after \"/1\" must be specified. (required)
* @param array $parameters Query parameters to apply to the current query. (optional)
* @param array $body Parameters to send with the custom request. (optional)
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return array<string, mixed>|object
*/
public function customPost($path, $parameters = null, $body = null, $requestOptions = [])
{
// verify the required parameter 'path' is set
if (!isset($path)) {
throw new \InvalidArgumentException(
'Parameter `path` is required when calling `customPost`.'
);
}
$resourcePath = '/{path}';
$queryParameters = [];
$headers = [];
$httpBody = isset($body) ? $body : [];
if (null !== $parameters) {
$queryParameters = $parameters;
}
// path params
if (null !== $path) {
$resourcePath = str_replace(
'{path}',
$path,
$resourcePath
);
}
return $this->sendRequest('POST', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* This method allow you to send requests to the Algolia REST API.
*
* @param string $path Path of the endpoint, anything after \"/1\" must be specified. (required)
* @param array $parameters Query parameters to apply to the current query. (optional)
* @param array $body Parameters to send with the custom request. (optional)
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return array<string, mixed>|object
*/
public function customPut($path, $parameters = null, $body = null, $requestOptions = [])
{
// verify the required parameter 'path' is set
if (!isset($path)) {
throw new \InvalidArgumentException(
'Parameter `path` is required when calling `customPut`.'
);
}
$resourcePath = '/{path}';
$queryParameters = [];
$headers = [];
$httpBody = isset($body) ? $body : [];
if (null !== $parameters) {
$queryParameters = $parameters;
}
// path params
if (null !== $path) {
$resourcePath = str_replace(
'{path}',
$path,
$resourcePath
);
}
return $this->sendRequest('PUT', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* Deletes the API key.
*
* Required API Key ACLs:
* - admin
*
* @param string $key API key. (required)
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return \Algolia\AlgoliaSearch\Model\Search\DeleteApiKeyResponse|array<string, mixed>
*/
public function deleteApiKey($key, $requestOptions = [])
{
// verify the required parameter 'key' is set
if (!isset($key)) {
throw new \InvalidArgumentException(
'Parameter `key` is required when calling `deleteApiKey`.'
);
}
$resourcePath = '/1/keys/{key}';
$queryParameters = [];
$headers = [];
$httpBody = null;
// path params
if (null !== $key) {
$resourcePath = str_replace(
'{key}',
ObjectSerializer::toPathValue($key),
$resourcePath
);
}
return $this->sendRequest('DELETE', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* This operation doesn't accept empty queries or filters. It's more efficient to get a list of object IDs with the [`browse` operation](#tag/Search/operation/browse), and then delete the records using the [`batch` operation](tag/Records/operation/batch).
*
* Required API Key ACLs:
* - deleteIndex
*
* @param string $indexName Name of the index on which to perform the operation. (required)
* @param array $deleteByParams deleteByParams (required)
* - $deleteByParams['facetFilters'] => (array)
* - $deleteByParams['filters'] => (string) Filter expression to only include items that match the filter criteria in the response. You can use these filter expressions: - **Numeric filters.** `<facet> <op> <number>`, where `<op>` is one of `<`, `<=`, `=`, `!=`, `>`, `>=`. - **Ranges.** `<facet>:<lower> TO <upper>` where `<lower>` and `<upper>` are the lower and upper limits of the range (inclusive). - **Facet filters.** `<facet>:<value>` where `<facet>` is a facet attribute (case-sensitive) and `<value>` a facet value. - **Tag filters.** `_tags:<value>` or just `<value>` (case-sensitive). - **Boolean filters.** `<facet>: true | false`. You can combine filters with `AND`, `OR`, and `NOT` operators with the following restrictions: - You can only combine filters of the same type with `OR`. **Not supported:** `facet:value OR num > 3`. - You can't use `NOT` with combinations of filters. **Not supported:** `NOT(facet:value OR facet:value)` - You can't combine conjunctions (`AND`) with `OR`. **Not supported:** `facet:value OR (facet:value AND facet:value)` Use quotes around your filters, if the facet attribute name or facet value has spaces, keywords (`OR`, `AND`, `NOT`), or quotes. If a facet attribute is an array, the filter matches if it matches at least one element of the array. For more information, see [Filters](https://www.algolia.com/doc/guides/managing-results/refine-results/filtering/).
* - $deleteByParams['numericFilters'] => (array)
* - $deleteByParams['tagFilters'] => (array)
* - $deleteByParams['aroundLatLng'] => (string) Coordinates for the center of a circle, expressed as a comma-separated string of latitude and longitude. Only records included within circle around this central location are included in the results. The radius of the circle is determined by the `aroundRadius` and `minimumAroundRadius` settings. This parameter is ignored if you also specify `insidePolygon` or `insideBoundingBox`.
* - $deleteByParams['aroundRadius'] => (array)
* - $deleteByParams['insideBoundingBox'] => (array) Coordinates for a rectangular area in which to search. Each bounding box is defined by the two opposite points of its diagonal, and expressed as latitude and longitude pair: `[p1 lat, p1 long, p2 lat, p2 long]`. Provide multiple bounding boxes as nested arrays. For more information, see [rectangular area](https://www.algolia.com/doc/guides/managing-results/refine-results/geolocation/#filtering-inside-rectangular-or-polygonal-areas).
* - $deleteByParams['insidePolygon'] => (array) Coordinates of a polygon in which to search. Polygons are defined by 3 to 10,000 points. Each point is represented by its latitude and longitude. Provide multiple polygons as nested arrays. For more information, see [filtering inside polygons](https://www.algolia.com/doc/guides/managing-results/refine-results/geolocation/#filtering-inside-rectangular-or-polygonal-areas). This parameter is ignored if you also specify `insideBoundingBox`.
*
* @see \Algolia\AlgoliaSearch\Model\Search\DeleteByParams
*
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return \Algolia\AlgoliaSearch\Model\Search\DeletedAtResponse|array<string, mixed>
*/
public function deleteBy($indexName, $deleteByParams, $requestOptions = [])
{
// verify the required parameter 'indexName' is set
if (!isset($indexName)) {
throw new \InvalidArgumentException(
'Parameter `indexName` is required when calling `deleteBy`.'
);
}
// verify the required parameter 'deleteByParams' is set
if (!isset($deleteByParams)) {
throw new \InvalidArgumentException(
'Parameter `deleteByParams` is required when calling `deleteBy`.'
);
}
$resourcePath = '/1/indexes/{indexName}/deleteByQuery';
$queryParameters = [];
$headers = [];
$httpBody = $deleteByParams;
// path params
if (null !== $indexName) {
$resourcePath = str_replace(
'{indexName}',
ObjectSerializer::toPathValue($indexName),
$resourcePath
);
}
return $this->sendRequest('POST', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* Deletes an index and all its settings. - Deleting an index doesn't delete its analytics data. - If you try to delete a non-existing index, the operation is ignored without warning. - If the index you want to delete has replica indices, the replicas become independent indices. - If the index you want to delete is a replica index, you must first unlink it from its primary index before you can delete it. For more information, see [Delete replica indices](https://www.algolia.com/doc/guides/managing-results/refine-results/sorting/how-to/deleting-replicas/).
*
* Required API Key ACLs:
* - deleteIndex
*
* @param string $indexName Name of the index on which to perform the operation. (required)
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return \Algolia\AlgoliaSearch\Model\Search\DeletedAtResponse|array<string, mixed>
*/
public function deleteIndex($indexName, $requestOptions = [])
{
// verify the required parameter 'indexName' is set
if (!isset($indexName)) {
throw new \InvalidArgumentException(
'Parameter `indexName` is required when calling `deleteIndex`.'
);
}
$resourcePath = '/1/indexes/{indexName}';
$queryParameters = [];
$headers = [];
$httpBody = null;
// path params
if (null !== $indexName) {
$resourcePath = str_replace(
'{indexName}',
ObjectSerializer::toPathValue($indexName),
$resourcePath
);
}
return $this->sendRequest('DELETE', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* Deletes a record by its object ID. To delete more than one record, use the [`batch` operation](#tag/Records/operation/batch). To delete records matching a query, use the [`deleteByQuery` operation](#tag/Records/operation/deleteBy).
*
* Required API Key ACLs:
* - deleteObject
*
* @param string $indexName Name of the index on which to perform the operation. (required)
* @param string $objectID Unique record identifier. (required)
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return \Algolia\AlgoliaSearch\Model\Search\DeletedAtResponse|array<string, mixed>
*/
public function deleteObject($indexName, $objectID, $requestOptions = [])
{
// verify the required parameter 'indexName' is set
if (!isset($indexName)) {
throw new \InvalidArgumentException(
'Parameter `indexName` is required when calling `deleteObject`.'
);
}
// verify the required parameter 'objectID' is set
if (!isset($objectID)) {
throw new \InvalidArgumentException(
'Parameter `objectID` is required when calling `deleteObject`.'
);
}
$resourcePath = '/1/indexes/{indexName}/{objectID}';
$queryParameters = [];
$headers = [];
$httpBody = null;
// path params
if (null !== $indexName) {
$resourcePath = str_replace(
'{indexName}',
ObjectSerializer::toPathValue($indexName),
$resourcePath
);
}
// path params
if (null !== $objectID) {
$resourcePath = str_replace(
'{objectID}',
ObjectSerializer::toPathValue($objectID),
$resourcePath
);
}
return $this->sendRequest('DELETE', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* Deletes a rule by its ID. To find the object ID for rules, use the [`search` operation](#tag/Rules/operation/searchRules).
*
* Required API Key ACLs:
* - editSettings
*
* @param string $indexName Name of the index on which to perform the operation. (required)
* @param string $objectID Unique identifier of a rule object. (required)
* @param bool $forwardToReplicas Whether changes are applied to replica indices. (optional)
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return \Algolia\AlgoliaSearch\Model\Search\UpdatedAtResponse|array<string, mixed>
*/
public function deleteRule($indexName, $objectID, $forwardToReplicas = null, $requestOptions = [])
{
// verify the required parameter 'indexName' is set
if (!isset($indexName)) {
throw new \InvalidArgumentException(
'Parameter `indexName` is required when calling `deleteRule`.'
);
}
// verify the required parameter 'objectID' is set
if (!isset($objectID)) {
throw new \InvalidArgumentException(
'Parameter `objectID` is required when calling `deleteRule`.'
);
}
$resourcePath = '/1/indexes/{indexName}/rules/{objectID}';
$queryParameters = [];
$headers = [];
$httpBody = null;
if (null !== $forwardToReplicas) {
$queryParameters['forwardToReplicas'] = $forwardToReplicas;
}
// path params
if (null !== $indexName) {
$resourcePath = str_replace(
'{indexName}',
ObjectSerializer::toPathValue($indexName),
$resourcePath
);
}
// path params
if (null !== $objectID) {
$resourcePath = str_replace(
'{objectID}',
ObjectSerializer::toPathValue($objectID),
$resourcePath
);
}
return $this->sendRequest('DELETE', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions);
}
/**
* Deletes a source from the list of allowed sources.
*
* Required API Key ACLs:
* - admin
*
* @param string $source IP address range of the source. (required)
* @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions
*
* @return \Algolia\AlgoliaSearch\Model\Search\DeleteSourceResponse|array<string, mixed>
*/
public function deleteSource($source, $requestOptions = [])
{
// verify the required parameter 'source' is set
if (!isset($source)) {
throw new \InvalidArgumentException(
'Parameter `source` is required when calling `deleteSource`.'
);
}