Skip to content

docs(php): Add remaining guides #699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function get($clientName)
return self::$value[$clientName];
}

public static function addCustomAlgoliaAgent(
public static function addAlgoliaAgent(
$clientName,
$segment,
$version
Expand Down
76 changes: 70 additions & 6 deletions website/docs/clients/guides/copy-or-move-index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,36 @@ const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');
const { taskID } = await client.operationIndex({
indexName: '<SOURCE_INDEX_NAME>',
operationIndexParams: {
destination: '<DESTINATION_INDEX_NAME>',
operation: 'copy',
destination: '<DESTINATION_INDEX_NAME>',
},
});

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

</TabItem>
<TabItem value="php">

```php
$client = SearchClient::create(
'<YOUR_APP_ID>',
'<YOUR_APP_ID>'
);

$response = $client->operationIndex(
'<SOURCE_INDEX_NAME>',
[
'operation' => 'copy',
'destination' => '<DESTINATION_INDEX_NAME>',
]
);

// Poll the task status with defaults values
$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
```

</TabItem>
<TabItem value="java">

Expand All @@ -44,8 +65,8 @@ import com.algolia.model.search.*;
UpdatedAtResponse response = client.operationIndex(
"<SOURCE_INDEX_NAME>",
new OperationIndexParams()
.setDestination("<DESTINATION_INDEX_NAME>")
.setOperation(OperationType.COPY)
.setDestination("<DESTINATION_INDEX_NAME>")
);

// Poll the task status until it's done
Expand All @@ -70,15 +91,36 @@ const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');
const { taskID } = await client.operationIndex({
indexName: '<SOURCE_INDEX_NAME>',
operationIndexParams: {
destination: '<DESTINATION_INDEX_NAME>',
operation: 'move',
destination: '<DESTINATION_INDEX_NAME>',
},
});

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

</TabItem>
<TabItem value="php">

```php
$client = SearchClient::create(
'<YOUR_APP_ID>',
'<YOUR_APP_ID>'
);

$response = $client->operationIndex(
'<SOURCE_INDEX_NAME>',
[
'operation' => 'move',
'destination' => '<DESTINATION_INDEX_NAME>',
]
);

// Poll the task status with defaults values
$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
```

</TabItem>
<TabItem value="java">

Expand All @@ -88,8 +130,8 @@ import com.algolia.model.search.*;
UpdatedAtResponse response = client.operationIndex(
"<SOURCE_INDEX_NAME>",
new OperationIndexParams()
.setDestination("<DESTINATION_INDEX_NAME>")
.setOperation(OperationType.MOVE)
.setDestination("<DESTINATION_INDEX_NAME>")
);

// Poll the task status until it's done
Expand All @@ -116,8 +158,8 @@ const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');
const { taskID } = await client.operationIndex({
indexName: '<SOURCE_INDEX_NAME>',
operationIndexParams: {
destination: '<DESTINATION_INDEX_NAME>',
operation: 'move',
destination: '<DESTINATION_INDEX_NAME>',
scope: ['rules'],
},
});
Expand All @@ -126,6 +168,28 @@ const { taskID } = await client.operationIndex({
await client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID });
```

</TabItem>
<TabItem value="php">

```php
$client = SearchClient::create(
'<YOUR_APP_ID>',
'<YOUR_APP_ID>'
);

$response = $client->operationIndex(
'<SOURCE_INDEX_NAME>',
[
'operation' => 'move',
'destination' => '<DESTINATION_INDEX_NAME>',
'scope' => ['rules'],
]
);

// Poll the task status with defaults values
$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
```

</TabItem>
<TabItem value="java">

Expand All @@ -135,8 +199,8 @@ import com.algolia.model.search.*;
UpdatedAtResponse response = client.operationIndex(
"<SOURCE_INDEX_NAME>",
new OperationIndexParams()
.setDestination("<DESTINATION_INDEX_NAME>")
.setOperation(OperationType.MOVE)
.setDestination("<DESTINATION_INDEX_NAME>")
.addScope(ScopeType.RULES)
);

Expand Down
63 changes: 63 additions & 0 deletions website/docs/clients/guides/customized-client-usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ await client.search(
);
```

</TabItem>
<TabItem value="php">

```php
$client->search(
[
'requests' => [
[
'indexName' => '<YOUR_INDEX_NAME>',
'query' => '<YOUR_QUERY>',
'hitsPerPage' => 50,
],
]
],
[
// This header is added to the request
'headers' => ['additional-header' => 'hello'],
// As we re-define `hitsPerPage`, it will override the value defined in the method's parameters.
'queryParameters' => ['hitsPerPage' => 100],
]
);
```

</TabItem>
<TabItem value="java">

Expand Down Expand Up @@ -86,7 +109,23 @@ client.addAlgoliaAgent('my user agent', 'optional version');
```

</TabItem>
<TabItem value="php">

```php
$client = SearchClient::create(
'<YOUR_APP_ID>',
'<YOUR_APP_ID>'
);

// This will append `; my user agent (optional version)` to the current value of `User-Agent` for every requests
Algolia\AlgoliaSearch\Support\AlgoliaAgent::addAlgoliaAgent(
$client->getClientConfig()->getClientName(),
"my user agent",
"optional version"
);
```

</TabItem>
<TabItem value="java">

```java
Expand Down Expand Up @@ -124,7 +163,31 @@ const client = searchClient('<YOUR_APP_ID>', '<YOUR_API_KEY>', {
```

</TabItem>
<TabItem value="php">

> In PHP, the requests are handled by the HTTP Client (by default GuzzleHttpClient)

```php
use Algolia\AlgoliaSearch\Api\SearchClient;
use Algolia\AlgoliaSearch\Configuration\SearchConfig;
use Algolia\AlgoliaSearch\Http\HttpClientInterface;
use Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper;
use Algolia\AlgoliaSearch\RetryStrategy\ClusterHosts;

// Create a config and a clusterhosts objects with your credentials
$config = SearchConfig::create('<YOUR_APP_ID>', '<YOUR_API_KEY>');
$clusterHosts = ClusterHosts::createFromAppId('<YOUR_APP_ID>');

// Instanciate a MyHttpClient object implementing HttpClientInterface (replacing GuzzleHttpClient)
$myHttpClient = new MyHttpClient(...);
// Now create you custom Api wrapper
$apiWrapper = new ApiWrapper($myHttpClient, $config, $clusterHosts);

// Instanciate your client using the constructor
$client = new SearchClient($apiWrapper, $config);
```

</TabItem>
<TabItem value="java">

> Create your own requester by creating a class that implements `com.algolia.utils.Requester`, and use it by passing it to the client constructor.
Expand Down
35 changes: 35 additions & 0 deletions website/docs/clients/guides/wait-for-a-task-to-finish.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,41 @@ await client.waitForTask({
});
```

</TabItem>
<TabItem value="php">

```php
$client = SearchClient::create(
'<YOUR_APP_ID>',
'<YOUR_APP_ID>'
);

$response = $client->saveObject(
'<YOUR_INDEX_NAME>',
['title' => "My Algolia Object"],
$requestOptions
);

// Poll the task status with defaults values
$client->waitForTask('<YOUR_INDEX_NAME>', $response['taskID']);

// Poll the task status with your options
Algolia\AlgoliaSearch\Support\Helpers::retryUntil(
$client,
'getTask',
['<YOUR_INDEX_NAME>', $response['taskID'], $requestOptions],
function ($res) {
return 'published' === $res['status'];
},
100, // Number of maximum retries to do
5000, // Default timeout
// Calculation of the time to wait between tries
function ($timeout, $retryCount) {
return min($retryCount * 200, $timeout) * 1000;
}
);
```

</TabItem>
<TabItem value="java">

Expand Down
44 changes: 42 additions & 2 deletions website/docs/clients/migration-guides/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,24 @@ const { taskID } = await client.saveObject({
await client.waitForTask({ indexName: '<YOUR_INDEX_NAME>', taskID });
```

</TabItem>
<TabItem value="php">

```php
$client = SearchClient::create(
'<YOUR_APP_ID>',
'<YOUR_APP_ID>'
);

$response = $client->saveObject(
'<YOUR_INDEX_NAME>',
['title' => "My Algolia Object"],
);

// Poll the task status with defaults values
$client->waitForTask('<YOUR_INDEX_NAME>', $response['taskID']);
```

</TabItem>
<TabItem value="java">

Expand Down Expand Up @@ -180,16 +198,38 @@ const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');
const { taskID } = await client.operationIndex({
indexName: '<SOURCE_INDEX_NAME>',
operationIndexParams: {
destination: '<DESTINATION_INDEX_NAME>',
// Enum for either `copy` or `move`
operation: 'copy', // 'move'
destination: '<DESTINATION_INDEX_NAME>',
},
});

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

</TabItem>
<TabItem value="php">

```php
$client = SearchClient::create(
'<YOUR_APP_ID>',
'<YOUR_APP_ID>'
);

$response = $client->operationIndex(
'<SOURCE_INDEX_NAME>',
[
// Enum for either `copy` or `move`
'operation' => 'copy', // 'move'
'destination' => '<DESTINATION_INDEX_NAME>'
]
);

// Poll the task status until it's done
$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
```

</TabItem>
<TabItem value="java">

Expand All @@ -199,8 +239,8 @@ import com.algolia.model.search.*;
UpdatedAtResponse response = client.operationIndex(
"<SOURCE_INDEX_NAME>",
new OperationIndexParams()
.setDestination("<DESTINATION_INDEX_NAME>")
.setOperation(OperationType.COPY) // or MOVE
.setDestination("<DESTINATION_INDEX_NAME>")
);

// Poll the task status until it's done
Expand Down
Loading