Skip to content

Commit 108956e

Browse files
authored
docs(php): Add remaining guides (#699)
1 parent 873b1d6 commit 108956e

File tree

6 files changed

+262
-10
lines changed

6 files changed

+262
-10
lines changed

clients/algoliasearch-client-php/lib/Support/AlgoliaAgent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static function get($clientName)
1919
return self::$value[$clientName];
2020
}
2121

22-
public static function addCustomAlgoliaAgent(
22+
public static function addAlgoliaAgent(
2323
$clientName,
2424
$segment,
2525
$version

website/docs/clients/guides/copy-or-move-index.mdx

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,36 @@ const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');
2626
const { taskID } = await client.operationIndex({
2727
indexName: '<SOURCE_INDEX_NAME>',
2828
operationIndexParams: {
29-
destination: '<DESTINATION_INDEX_NAME>',
3029
operation: 'copy',
30+
destination: '<DESTINATION_INDEX_NAME>',
3131
},
3232
});
3333

3434
// Poll the task status until it's done
3535
await client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID });
3636
```
3737

38+
</TabItem>
39+
<TabItem value="php">
40+
41+
```php
42+
$client = SearchClient::create(
43+
'<YOUR_APP_ID>',
44+
'<YOUR_APP_ID>'
45+
);
46+
47+
$response = $client->operationIndex(
48+
'<SOURCE_INDEX_NAME>',
49+
[
50+
'operation' => 'copy',
51+
'destination' => '<DESTINATION_INDEX_NAME>',
52+
]
53+
);
54+
55+
// Poll the task status with defaults values
56+
$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
57+
```
58+
3859
</TabItem>
3960
<TabItem value="java">
4061

@@ -44,8 +65,8 @@ import com.algolia.model.search.*;
4465
UpdatedAtResponse response = client.operationIndex(
4566
"<SOURCE_INDEX_NAME>",
4667
new OperationIndexParams()
47-
.setDestination("<DESTINATION_INDEX_NAME>")
4868
.setOperation(OperationType.COPY)
69+
.setDestination("<DESTINATION_INDEX_NAME>")
4970
);
5071

5172
// Poll the task status until it's done
@@ -70,15 +91,36 @@ const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');
7091
const { taskID } = await client.operationIndex({
7192
indexName: '<SOURCE_INDEX_NAME>',
7293
operationIndexParams: {
73-
destination: '<DESTINATION_INDEX_NAME>',
7494
operation: 'move',
95+
destination: '<DESTINATION_INDEX_NAME>',
7596
},
7697
});
7798

7899
// Poll the task status until it's done
79100
await client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID });
80101
```
81102

103+
</TabItem>
104+
<TabItem value="php">
105+
106+
```php
107+
$client = SearchClient::create(
108+
'<YOUR_APP_ID>',
109+
'<YOUR_APP_ID>'
110+
);
111+
112+
$response = $client->operationIndex(
113+
'<SOURCE_INDEX_NAME>',
114+
[
115+
'operation' => 'move',
116+
'destination' => '<DESTINATION_INDEX_NAME>',
117+
]
118+
);
119+
120+
// Poll the task status with defaults values
121+
$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
122+
```
123+
82124
</TabItem>
83125
<TabItem value="java">
84126

@@ -88,8 +130,8 @@ import com.algolia.model.search.*;
88130
UpdatedAtResponse response = client.operationIndex(
89131
"<SOURCE_INDEX_NAME>",
90132
new OperationIndexParams()
91-
.setDestination("<DESTINATION_INDEX_NAME>")
92133
.setOperation(OperationType.MOVE)
134+
.setDestination("<DESTINATION_INDEX_NAME>")
93135
);
94136

95137
// Poll the task status until it's done
@@ -116,8 +158,8 @@ const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');
116158
const { taskID } = await client.operationIndex({
117159
indexName: '<SOURCE_INDEX_NAME>',
118160
operationIndexParams: {
119-
destination: '<DESTINATION_INDEX_NAME>',
120161
operation: 'move',
162+
destination: '<DESTINATION_INDEX_NAME>',
121163
scope: ['rules'],
122164
},
123165
});
@@ -126,6 +168,28 @@ const { taskID } = await client.operationIndex({
126168
await client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID });
127169
```
128170

171+
</TabItem>
172+
<TabItem value="php">
173+
174+
```php
175+
$client = SearchClient::create(
176+
'<YOUR_APP_ID>',
177+
'<YOUR_APP_ID>'
178+
);
179+
180+
$response = $client->operationIndex(
181+
'<SOURCE_INDEX_NAME>',
182+
[
183+
'operation' => 'move',
184+
'destination' => '<DESTINATION_INDEX_NAME>',
185+
'scope' => ['rules'],
186+
]
187+
);
188+
189+
// Poll the task status with defaults values
190+
$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
191+
```
192+
129193
</TabItem>
130194
<TabItem value="java">
131195

@@ -135,8 +199,8 @@ import com.algolia.model.search.*;
135199
UpdatedAtResponse response = client.operationIndex(
136200
"<SOURCE_INDEX_NAME>",
137201
new OperationIndexParams()
138-
.setDestination("<DESTINATION_INDEX_NAME>")
139202
.setOperation(OperationType.MOVE)
203+
.setDestination("<DESTINATION_INDEX_NAME>")
140204
.addScope(ScopeType.RULES)
141205
);
142206

website/docs/clients/guides/customized-client-usage.mdx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,29 @@ await client.search(
6969
);
7070
```
7171

72+
</TabItem>
73+
<TabItem value="php">
74+
75+
```php
76+
$client->search(
77+
[
78+
'requests' => [
79+
[
80+
'indexName' => '<YOUR_INDEX_NAME>',
81+
'query' => '<YOUR_QUERY>',
82+
'hitsPerPage' => 50,
83+
],
84+
]
85+
],
86+
[
87+
// This header is added to the request
88+
'headers' => ['additional-header' => 'hello'],
89+
// As we re-define `hitsPerPage`, it will override the value defined in the method's parameters.
90+
'queryParameters' => ['hitsPerPage' => 100],
91+
]
92+
);
93+
```
94+
7295
</TabItem>
7396
<TabItem value="java">
7497

@@ -115,7 +138,23 @@ client.addAlgoliaAgent('my user agent', 'optional version');
115138
```
116139

117140
</TabItem>
141+
<TabItem value="php">
142+
143+
```php
144+
$client = SearchClient::create(
145+
'<YOUR_APP_ID>',
146+
'<YOUR_APP_ID>'
147+
);
148+
149+
// This will append `; my user agent (optional version)` to the current value of `User-Agent` for every requests
150+
Algolia\AlgoliaSearch\Support\AlgoliaAgent::addAlgoliaAgent(
151+
$client->getClientConfig()->getClientName(),
152+
"my user agent",
153+
"optional version"
154+
);
155+
```
118156

157+
</TabItem>
119158
<TabItem value="java">
120159

121160
```java
@@ -153,7 +192,31 @@ const client = searchClient('<YOUR_APP_ID>', '<YOUR_API_KEY>', {
153192
```
154193

155194
</TabItem>
195+
<TabItem value="php">
196+
197+
> In PHP, the requests are handled by the HTTP Client (by default GuzzleHttpClient)
198+
199+
```php
200+
use Algolia\AlgoliaSearch\Api\SearchClient;
201+
use Algolia\AlgoliaSearch\Configuration\SearchConfig;
202+
use Algolia\AlgoliaSearch\Http\HttpClientInterface;
203+
use Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper;
204+
use Algolia\AlgoliaSearch\RetryStrategy\ClusterHosts;
205+
206+
// Create a config and a clusterhosts objects with your credentials
207+
$config = SearchConfig::create('<YOUR_APP_ID>', '<YOUR_API_KEY>');
208+
$clusterHosts = ClusterHosts::createFromAppId('<YOUR_APP_ID>');
156209

210+
// Instanciate a MyHttpClient object implementing HttpClientInterface (replacing GuzzleHttpClient)
211+
$myHttpClient = new MyHttpClient(...);
212+
// Now create you custom Api wrapper
213+
$apiWrapper = new ApiWrapper($myHttpClient, $config, $clusterHosts);
214+
215+
// Instanciate your client using the constructor
216+
$client = new SearchClient($apiWrapper, $config);
217+
```
218+
219+
</TabItem>
157220
<TabItem value="java">
158221

159222
> Create your own requester by creating a class that implements `com.algolia.utils.Requester`, and use it by passing it to the client constructor.

website/docs/clients/guides/wait-for-a-task-to-finish.mdx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,41 @@ await client.waitForTask({
4040
});
4141
```
4242

43+
</TabItem>
44+
<TabItem value="php">
45+
46+
```php
47+
$client = SearchClient::create(
48+
'<YOUR_APP_ID>',
49+
'<YOUR_APP_ID>'
50+
);
51+
52+
$response = $client->saveObject(
53+
'<YOUR_INDEX_NAME>',
54+
['title' => "My Algolia Object"],
55+
$requestOptions
56+
);
57+
58+
// Poll the task status with defaults values
59+
$client->waitForTask('<YOUR_INDEX_NAME>', $response['taskID']);
60+
61+
// Poll the task status with your options
62+
Algolia\AlgoliaSearch\Support\Helpers::retryUntil(
63+
$client,
64+
'getTask',
65+
['<YOUR_INDEX_NAME>', $response['taskID'], $requestOptions],
66+
function ($res) {
67+
return 'published' === $res['status'];
68+
},
69+
100, // Number of maximum retries to do
70+
5000, // Default timeout
71+
// Calculation of the time to wait between tries
72+
function ($timeout, $retryCount) {
73+
return min($retryCount * 200, $timeout) * 1000;
74+
}
75+
);
76+
```
77+
4378
</TabItem>
4479
<TabItem value="java">
4580

website/docs/clients/migration-guides/index.mdx

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,24 @@ const { taskID } = await client.saveObject({
135135
await client.waitForTask({ indexName: '<YOUR_INDEX_NAME>', taskID });
136136
```
137137

138+
</TabItem>
139+
<TabItem value="php">
140+
141+
```php
142+
$client = SearchClient::create(
143+
'<YOUR_APP_ID>',
144+
'<YOUR_APP_ID>'
145+
);
146+
147+
$response = $client->saveObject(
148+
'<YOUR_INDEX_NAME>',
149+
['title' => "My Algolia Object"],
150+
);
151+
152+
// Poll the task status with defaults values
153+
$client->waitForTask('<YOUR_INDEX_NAME>', $response['taskID']);
154+
```
155+
138156
</TabItem>
139157
<TabItem value="java">
140158

@@ -180,16 +198,38 @@ const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');
180198
const { taskID } = await client.operationIndex({
181199
indexName: '<SOURCE_INDEX_NAME>',
182200
operationIndexParams: {
183-
destination: '<DESTINATION_INDEX_NAME>',
184201
// Enum for either `copy` or `move`
185202
operation: 'copy', // 'move'
203+
destination: '<DESTINATION_INDEX_NAME>',
186204
},
187205
});
188206

189207
// Poll the task status until it's done
190208
await client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID });
191209
```
192210

211+
</TabItem>
212+
<TabItem value="php">
213+
214+
```php
215+
$client = SearchClient::create(
216+
'<YOUR_APP_ID>',
217+
'<YOUR_APP_ID>'
218+
);
219+
220+
$response = $client->operationIndex(
221+
'<SOURCE_INDEX_NAME>',
222+
[
223+
// Enum for either `copy` or `move`
224+
'operation' => 'copy', // 'move'
225+
'destination' => '<DESTINATION_INDEX_NAME>'
226+
]
227+
);
228+
229+
// Poll the task status until it's done
230+
$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
231+
```
232+
193233
</TabItem>
194234
<TabItem value="java">
195235

@@ -199,8 +239,8 @@ import com.algolia.model.search.*;
199239
UpdatedAtResponse response = client.operationIndex(
200240
"<SOURCE_INDEX_NAME>",
201241
new OperationIndexParams()
202-
.setDestination("<DESTINATION_INDEX_NAME>")
203242
.setOperation(OperationType.COPY) // or MOVE
243+
.setDestination("<DESTINATION_INDEX_NAME>")
204244
);
205245

206246
// Poll the task status until it's done

0 commit comments

Comments
 (0)