Skip to content

Commit 1117593

Browse files
committed
docs(php): add migration guide
1 parent bf0db47 commit 1117593

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

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

Lines changed: 39 additions & 0 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

@@ -190,6 +208,27 @@ const { taskID } = await client.operationIndex({
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+
'operation' => 'copy', // 'move'
224+
'destination' => '<DESTINATION_INDEX_NAME>'
225+
]
226+
);
227+
228+
// Poll the task status until it's done
229+
$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
230+
```
231+
193232
</TabItem>
194233
<TabItem value="java">
195234

website/docs/clients/migration-guides/php.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,54 @@
22
title: PHP
33
---
44

5-
WIP
5+
| Previous | Latest | Description |
6+
| -------------------- | :------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
7+
| `"algolia/algoliasearch-client-php": "^3.2"` | `"algolia/algoliasearch-client-php": "^4.0"` | **During the beta phase**, the clients are available under the package 4.x.x-alpha , you can find a full list [here](https://packagist.org/packages/algolia/algoliasearch-client-php). |
8+
| `Algolia\AlgoliaSearch` | `Algolia\AlgoliaSearch\Api` | Exported clients have now the name suffixed by `Api`. |
9+
10+
### Usage
11+
12+
To get started, first uninstall the previously added clients.
13+
14+
```bash
15+
composer remove algolia/algoliasearch-client-php
16+
```
17+
18+
You can now install the `Algoliasearch` clients.
19+
20+
```bash
21+
composer require algolia/algoliasearch-client-php "^4.0"
22+
```
23+
24+
You can continue this guide on [our installation page](/docs/clients/installation).
25+
26+
### Methods targeting an `indexName`
27+
28+
Prior to the `initIndex` removal stated in the [common breaking changes](/docs/clients/migration-guides/#common-breaking-changes), all methods previously available at the `initIndex` level requires the `indexName` to be sent with the query.
29+
30+
```php
31+
use Algolia\AlgoliaSearch\Api\SearchClient;
32+
33+
$client = SearchClient::create(
34+
'<YOUR_APP_ID>',
35+
'<YOUR_API_KEY>'
36+
);
37+
38+
// only query string
39+
$searchResults = $client->search([
40+
'requests' => [
41+
['indexName' => '<YOUR_INDEX_NAME>', 'query' =>'<YOUR_QUERY>'],
42+
],
43+
]);
44+
45+
$searchResults2 = $client->search([
46+
'requests' => [
47+
[
48+
'indexName' => '<YOUR_INDEX_NAME>',
49+
'query' => '<YOUR_QUERY>',
50+
'attributesToRetrieve' => ['firstname', 'lastname'],
51+
'hitsPerPage' => 50,
52+
],
53+
],
54+
]);
55+
```

0 commit comments

Comments
 (0)