|
2 | 2 | title: PHP
|
3 | 3 | ---
|
4 | 4 |
|
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