-
Notifications
You must be signed in to change notification settings - Fork 21
/
AbstractClient.php
824 lines (722 loc) · 24.4 KB
/
AbstractClient.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
<?php
/**
* This file is part of the Elastic App Search PHP Client package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Elastic\AppSearch\Client;
/**
* Client implementation.
*
* @package Elastic\AppSearch\Client
*/
abstract class AbstractClient extends \Elastic\OpenApi\Codegen\AbstractClient
{
// phpcs:disable
/**
* Add a source engine to an existing meta engine.
*
* Documentation: https://swiftype.com/documentation/app-search/api/meta-engines#add-source-engines
*
* @param string $engineName Name of the engine.
* @param array $sourceEngines List of engine ids.
*
* @return array
*/
public function addMetaEngineSource($engineName, $sourceEngines)
{
$params = [
'engine_name' => $engineName,
];
$endpoint = $this->getEndpoint('AddMetaEngineSource');
$endpoint->setParams($params);
$endpoint->setBody($sourceEngines);
return $this->performRequest($endpoint);
}
/**
* Create a new curation.
*
* Documentation: https://swiftype.com/documentation/app-search/api/curations#create
*
* @param string $engineName Name of the engine.
* @param array $queries List of affected search queries.
* @param array $promotedDocIds List of promoted document ids.
* @param array $hiddenDocIds List of hidden document ids.
*
* @return array
*/
public function createCuration($engineName, $queries, $promotedDocIds = null, $hiddenDocIds = null)
{
$params = [
'engine_name' => $engineName,
'queries' => $queries,
'promoted' => $promotedDocIds,
'hidden' => $hiddenDocIds,
];
$endpoint = $this->getEndpoint('CreateCuration');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Create a new synonym set.
*
* Documentation: https://swiftype.com/documentation/app-search/api/synonyms#create
*
* @param string $engineName Name of the engine.
* @param array $synonyms List of synonyms words.
*
* @return array
*/
public function createSynonymSet($engineName, $synonyms)
{
$params = [
'engine_name' => $engineName,
'synonyms' => $synonyms,
];
$endpoint = $this->getEndpoint('CreateSynonymSet');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Delete a curation by id.
*
* Documentation: https://swiftype.com/documentation/app-search/api/curations#destroy
*
* @param string $engineName Name of the engine.
* @param string $curationId Curation id.
*
* @return array
*/
public function deleteCuration($engineName, $curationId)
{
$params = [
'engine_name' => $engineName,
'curation_id' => $curationId,
];
$endpoint = $this->getEndpoint('DeleteCuration');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Delete documents by id.
*
* Documentation: https://swiftype.com/documentation/app-search/api/documents#partial
*
* @param string $engineName Name of the engine.
* @param array $documentIds List of document ids.
*
* @return array
*/
public function deleteDocuments($engineName, $documentIds)
{
$params = [
'engine_name' => $engineName,
];
$endpoint = $this->getEndpoint('DeleteDocuments');
$endpoint->setParams($params);
$endpoint->setBody($documentIds);
return $this->performRequest($endpoint);
}
/**
* Delete an engine by name.
*
* Documentation: https://swiftype.com/documentation/app-search/api/engines#delete
*
* @param string $engineName Name of the engine.
*
* @return array
*/
public function deleteEngine($engineName)
{
$params = [
'engine_name' => $engineName,
];
$endpoint = $this->getEndpoint('DeleteEngine');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Delete a source engine from a meta engine.
*
* Documentation: https://swiftype.com/documentation/app-search/api/meta-engines#remove-source-engines
*
* @param string $engineName Name of the engine.
* @param array $sourceEngines List of engine ids.
*
* @return array
*/
public function deleteMetaEngineSource($engineName, $sourceEngines)
{
$params = [
'engine_name' => $engineName,
];
$endpoint = $this->getEndpoint('DeleteMetaEngineSource');
$endpoint->setParams($params);
$endpoint->setBody($sourceEngines);
return $this->performRequest($endpoint);
}
/**
* Delete a synonym set by id.
*
* Documentation: https://swiftype.com/documentation/app-search/api/synonyms#delete
*
* @param string $engineName Name of the engine.
* @param string $synonymSetId Synonym set id.
*
* @return array
*/
public function deleteSynonymSet($engineName, $synonymSetId)
{
$params = [
'engine_name' => $engineName,
'synonym_set_id' => $synonymSetId,
];
$endpoint = $this->getEndpoint('DeleteSynonymSet');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Creates a new engine.
*
* Documentation: https://swiftype.com/documentation/app-search/api/engines#create
*
* @param string $name Engine name.
* @param string $language Engine language (null for universal).
* @param string $type Engine type.
* @param array $sourceEngines Sources engines list.
*
* @return array
*/
protected function doCreateEngine($name, $language = null, $type = 'default', $sourceEngines = null)
{
$params = [
'name' => $name,
'language' => $language,
'type' => $type,
'source_engines' => $sourceEngines,
];
$endpoint = $this->getEndpoint('DoCreateEngine');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* The API Log displays API request and response data at the Engine level.
*
* Documentation: https://swiftype.com/documentation/app-search/api/logs
*
* @param string $engineName Name of the engine.
* @param string $fromDate Filter date from.
* @param string $toDate Filter date to.
* @param string $currentPage The page to fetch. Defaults to 1.
* @param string $pageSize The number of results per page.
* @param string $query Use this to specify a particular endpoint, like analytics, search, curations and so on.
* @param string $httpStatusFilter Filter based on a particular status code: 400, 401, 403, 429, 200.
* @param string $httpMethodFilter Filter based on a particular HTTP method: GET, POST, PUT, PATCH, DELETE.
* @param string $sortDirection Would you like to have your results ascending, oldest to newest, or descending, newest to oldest?
*
* @return array
*/
public function getApiLogs($engineName, $fromDate, $toDate, $currentPage = null, $pageSize = null, $query = null, $httpStatusFilter = null, $httpMethodFilter = null, $sortDirection = null)
{
$params = [
'engine_name' => $engineName,
'filters.date.from' => $fromDate,
'filters.date.to' => $toDate,
'page.current' => $currentPage,
'page.size' => $pageSize,
'query' => $query,
'filters.status' => $httpStatusFilter,
'filters.method' => $httpMethodFilter,
'sort_direction' => $sortDirection,
];
$endpoint = $this->getEndpoint('GetApiLogs');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Returns the number of clicks and total number of queries over a period.
*
* Documentation: https://swiftype.com/documentation/app-search/api/analytics/counts
*
* @param string $engineName Name of the engine.
* @param array $filters Analytics filters
* @param string $interval You can define an interval along with your date range. Can be either hour or day.
*
* @return array
*/
public function getCountAnalytics($engineName, $filters = null, $interval = null)
{
$params = [
'engine_name' => $engineName,
'filters' => $filters,
'interval' => $interval,
];
$endpoint = $this->getEndpoint('GetCountAnalytics');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Retrieve a curation by id.
*
* Documentation: https://swiftype.com/documentation/app-search/api/curations#single
*
* @param string $engineName Name of the engine.
* @param string $curationId Curation id.
*
* @return array
*/
public function getCuration($engineName, $curationId)
{
$params = [
'engine_name' => $engineName,
'curation_id' => $curationId,
];
$endpoint = $this->getEndpoint('GetCuration');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Retrieves one or more documents by id.
*
* Documentation: https://swiftype.com/documentation/app-search/api/documents#get
*
* @param string $engineName Name of the engine.
* @param array $documentIds List of document ids.
*
* @return array
*/
public function getDocuments($engineName, $documentIds)
{
$params = [
'engine_name' => $engineName,
];
$endpoint = $this->getEndpoint('GetDocuments');
$endpoint->setParams($params);
$endpoint->setBody($documentIds);
return $this->performRequest($endpoint);
}
/**
* Retrieves an engine by name.
*
* Documentation: https://swiftype.com/documentation/app-search/api/engines#get
*
* @param string $engineName Name of the engine.
*
* @return array
*/
public function getEngine($engineName)
{
$params = [
'engine_name' => $engineName,
];
$endpoint = $this->getEndpoint('GetEngine');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Retrieve current schema for then engine.
*
* Documentation: https://swiftype.com/documentation/app-search/api/schema#read
*
* @param string $engineName Name of the engine.
*
* @return array
*/
public function getSchema($engineName)
{
$params = [
'engine_name' => $engineName,
];
$endpoint = $this->getEndpoint('GetSchema');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Retrive current search settings for the engine.
*
* Documentation: https://swiftype.com/documentation/app-search/api/search-settings#show
*
* @param string $engineName Name of the engine.
*
* @return array
*/
public function getSearchSettings($engineName)
{
$params = [
'engine_name' => $engineName,
];
$endpoint = $this->getEndpoint('GetSearchSettings');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Retrieve a synonym set by id.
*
* Documentation: https://swiftype.com/documentation/app-search/api/synonyms#list-one
*
* @param string $engineName Name of the engine.
* @param string $synonymSetId Synonym set id.
*
* @return array
*/
public function getSynonymSet($engineName, $synonymSetId)
{
$params = [
'engine_name' => $engineName,
'synonym_set_id' => $synonymSetId,
];
$endpoint = $this->getEndpoint('GetSynonymSet');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Returns the number of clicks received by a document in descending order.
*
* Documentation: https://swiftype.com/documentation/app-search/api/analytics/clicks
*
* @param string $engineName Name of the engine.
* @param string $query Filter clicks over a search query.
* @param string $pageSize The number of results per page.
* @param array $filters Analytics filters
*
* @return array
*/
public function getTopClicksAnalytics($engineName, $query = null, $pageSize = null, $filters = null)
{
$params = [
'engine_name' => $engineName,
'query' => $query,
'page.size' => $pageSize,
'filters' => $filters,
];
$endpoint = $this->getEndpoint('GetTopClicksAnalytics');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Returns queries anlaytics by usage count.
*
* Documentation: https://swiftype.com/documentation/app-search/api/analytics/queries
*
* @param string $engineName Name of the engine.
* @param string $pageSize The number of results per page.
* @param array $filters Analytics filters
*
* @return array
*/
public function getTopQueriesAnalytics($engineName, $pageSize = null, $filters = null)
{
$params = [
'engine_name' => $engineName,
'page.size' => $pageSize,
'filters' => $filters,
];
$endpoint = $this->getEndpoint('GetTopQueriesAnalytics');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Create or update documents.
*
* Documentation: https://swiftype.com/documentation/app-search/api/documents#create
*
* @param string $engineName Name of the engine.
* @param array $documents List of document to index.
*
* @return array
*/
public function indexDocuments($engineName, $documents)
{
$params = [
'engine_name' => $engineName,
];
$endpoint = $this->getEndpoint('IndexDocuments');
$endpoint->setParams($params);
$endpoint->setBody($documents);
return $this->performRequest($endpoint);
}
/**
* Retrieve available curations for the engine.
*
* Documentation: https://swiftype.com/documentation/app-search/api/curations#read
*
* @param string $engineName Name of the engine.
* @param string $currentPage The page to fetch. Defaults to 1.
* @param string $pageSize The number of results per page.
*
* @return array
*/
public function listCurations($engineName, $currentPage = null, $pageSize = null)
{
$params = [
'engine_name' => $engineName,
'page.current' => $currentPage,
'page.size' => $pageSize,
];
$endpoint = $this->getEndpoint('ListCurations');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* List all available documents with optional pagination support.
*
* Documentation: https://swiftype.com/documentation/app-search/api/documents#list
*
* @param string $engineName Name of the engine.
* @param string $currentPage The page to fetch. Defaults to 1.
* @param string $pageSize The number of results per page.
*
* @return array
*/
public function listDocuments($engineName, $currentPage = null, $pageSize = null)
{
$params = [
'engine_name' => $engineName,
'page.current' => $currentPage,
'page.size' => $pageSize,
];
$endpoint = $this->getEndpoint('ListDocuments');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Retrieves all engines with optional pagination support.
*
* Documentation: https://swiftype.com/documentation/app-search/api/engines#list
*
* @param string $currentPage The page to fetch. Defaults to 1.
* @param string $pageSize The number of results per page.
*
* @return array
*/
public function listEngines($currentPage = null, $pageSize = null)
{
$params = [
'page.current' => $currentPage,
'page.size' => $pageSize,
];
$endpoint = $this->getEndpoint('ListEngines');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Retrieve available synonym sets for the engine.
*
* Documentation: https://swiftype.com/documentation/app-search/api/synonyms#get
*
* @param string $engineName Name of the engine.
* @param string $currentPage The page to fetch. Defaults to 1.
* @param string $pageSize The number of results per page.
*
* @return array
*/
public function listSynonymSets($engineName, $currentPage = null, $pageSize = null)
{
$params = [
'engine_name' => $engineName,
'page.current' => $currentPage,
'page.size' => $pageSize,
];
$endpoint = $this->getEndpoint('ListSynonymSets');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Send data about clicked results.
*
* Documentation: https://swiftype.com/documentation/app-search/api/clickthrough
*
* @param string $engineName Name of the engine.
* @param string $queryText Search query text.
* @param string $documentId The id of the document that was clicked on.
* @param string $requestId The request id returned in the meta tag of a search API response.
* @param array $tags Array of strings representing additional information you wish to track with the clickthrough.
*
* @return array
*/
public function logClickthrough($engineName, $queryText, $documentId, $requestId = null, $tags = null)
{
$params = [
'engine_name' => $engineName,
'query' => $queryText,
'document_id' => $documentId,
'request_id' => $requestId,
'tags' => $tags,
];
$endpoint = $this->getEndpoint('LogClickthrough');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Run several search in the same request.
*
* Documentation: https://swiftype.com/documentation/app-search/api/search#multi
*
* @param string $engineName Name of the engine.
* @param array $queries Search queries.
*
* @return array
*/
public function multiSearch($engineName, $queries)
{
$params = [
'engine_name' => $engineName,
'queries' => $queries,
];
$endpoint = $this->getEndpoint('MultiSearch');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Provide relevant query suggestions for incomplete queries.
*
* Documentation: https://swiftype.com/documentation/app-search/api/query-suggestion
*
* @param string $engineName Name of the engine.
* @param string $query A partial query for which to receive suggestions.
* @param array $fields List of fields to use to generate suggestions. Defaults to all text fields.
* @param int $size Number of query suggestions to return. Must be between 1 and 20. Defaults to 5.
*
* @return array
*/
public function querySuggestion($engineName, $query, $fields = null, $size = null)
{
$params = [
'engine_name' => $engineName,
'query' => $query,
'types.documents.fields' => $fields,
'size' => $size,
];
$endpoint = $this->getEndpoint('QuerySuggestion');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Reset search settings for the engine.
*
* Documentation: https://swiftype.com/documentation/app-search/api/search-settings#reset
*
* @param string $engineName Name of the engine.
*
* @return array
*/
public function resetSearchSettings($engineName)
{
$params = [
'engine_name' => $engineName,
];
$endpoint = $this->getEndpoint('ResetSearchSettings');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Allows you to search over, facet and filter your data.
*
* Documentation: https://swiftype.com/documentation/app-search/api/search
*
* @param string $engineName Name of the engine.
* @param string $queryText Search query text.
* @param array $searchRequestParams Search request parameters.
*
* @return array
*/
public function search($engineName, $queryText, $searchRequestParams = null)
{
$params = [
'engine_name' => $engineName,
'query' => $queryText,
];
$endpoint = $this->getEndpoint('Search');
$endpoint->setParams($params);
$endpoint->setBody($searchRequestParams);
return $this->performRequest($endpoint);
}
/**
* Update an existing curation.
*
* Documentation: https://swiftype.com/documentation/app-search/api/curations#update
*
* @param string $engineName Name of the engine.
* @param string $curationId Curation id.
* @param array $queries List of affected search queries.
* @param array $promotedDocIds List of promoted document ids.
* @param array $hiddenDocIds List of hidden document ids.
*
* @return array
*/
public function updateCuration($engineName, $curationId, $queries, $promotedDocIds = null, $hiddenDocIds = null)
{
$params = [
'engine_name' => $engineName,
'curation_id' => $curationId,
'queries' => $queries,
'promoted' => $promotedDocIds,
'hidden' => $hiddenDocIds,
];
$endpoint = $this->getEndpoint('UpdateCuration');
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
/**
* Partial update of documents.
*
* Documentation: https://swiftype.com/documentation/app-search/api/documents#partial
*
* @param string $engineName Name of the engine.
* @param array $documents List of document to update.
*
* @return array
*/
public function updateDocuments($engineName, $documents)
{
$params = [
'engine_name' => $engineName,
];
$endpoint = $this->getEndpoint('UpdateDocuments');
$endpoint->setParams($params);
$endpoint->setBody($documents);
return $this->performRequest($endpoint);
}
/**
* Update schema for the current engine.
*
* Documentation: https://swiftype.com/documentation/app-search/api/schema#patch
*
* @param string $engineName Name of the engine.
* @param array $schema Schema description.
*
* @return array
*/
public function updateSchema($engineName, $schema)
{
$params = [
'engine_name' => $engineName,
];
$endpoint = $this->getEndpoint('UpdateSchema');
$endpoint->setParams($params);
$endpoint->setBody($schema);
return $this->performRequest($endpoint);
}
/**
* Update search settings for the engine.
*
* Documentation: https://swiftype.com/documentation/app-search/api/search-settings#update
*
* @param string $engineName Name of the engine.
* @param array $searchSettings Search settings.
*
* @return array
*/
public function updateSearchSettings($engineName, $searchSettings)
{
$params = [
'engine_name' => $engineName,
];
$endpoint = $this->getEndpoint('UpdateSearchSettings');
$endpoint->setParams($params);
$endpoint->setBody($searchSettings);
return $this->performRequest($endpoint);
}
// phpcs:enable
}