Skip to content

docs: Add php code samples #502

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 4 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
72 changes: 69 additions & 3 deletions website/docs/api-clients/guides/filtering-your-search.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Initially, filter attributes must be defined as facets, using the `attributesFor
groupId="language"
defaultValue="js"
values={[
{ label: 'JavaScript', value: 'js', }
{ label: 'JavaScript', value: 'js', },
{ label: 'PHP', value: 'php', }
]
}>
<TabItem value="js">
Expand All @@ -35,6 +36,15 @@ await client.setSettings({
});
```

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

```php
$client->setSettings(
'<YOUR_INDEX_NAME>',
['attributesForFaceting' => ['actor', 'filterOnly(category)', 'searchable(publisher)']]
);
```
</TabItem>
</Tabs>

Expand All @@ -48,7 +58,8 @@ The actual filtering of records is performed at query time, not at indexing time
groupId="language"
defaultValue="js"
values={[
{ label: 'JavaScript', value: 'js', }
{ label: 'JavaScript', value: 'js', },
{ label: 'PHP', value: 'php', }
]
}>
<TabItem value="js">
Expand Down Expand Up @@ -82,6 +93,38 @@ await client.search({
});
```

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

```php
// Only "Scarlett Johansson" actor
$client->search(
'<YOUR_INDEX_NAME>',
[
'query' => '<YOUR_QUERY>',
'filters' => 'actor:Scarlett Johansson',
]
);

// Only "Tom Cruise" or "Scarlett Johansson" actor
$client->search(
'<YOUR_INDEX_NAME>',
[
'query' => '<YOUR_QUERY>',
'filters' => 'actor:Tom Cruise OR actor:Scarlett Johansson',
]
);

// Everything but "Nicolas Cage" actor
$client->search(
'<YOUR_INDEX_NAME>',
[
'query' => '<YOUR_QUERY>',
'filters' => 'NOT actor:Nicolas Cage',
]
);

```
</TabItem>
</Tabs>

Expand All @@ -91,7 +134,8 @@ await client.search({
groupId="language"
defaultValue="js"
values={[
{ label: 'JavaScript', value: 'js', }
{ label: 'JavaScript', value: 'js', },
{ label: 'PHP', value: 'php', }
]
}>
<TabItem value="js">
Expand All @@ -116,5 +160,27 @@ await client.search({
});
```

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

```php
// Only "Scarlett Johansson" actor
$client->search(
'<YOUR_INDEX_NAME>',
[
'query' => '<YOUR_QUERY>',
'facetFilters' => ['actor:Scarlett Johansson'],
]
);

// Only "Tom Cruise" or "Scarlett Johansson" actor
$client->search(
'<YOUR_INDEX_NAME>',
[
'query' => '<YOUR_QUERY>',
'facetFilters' => ['actor:Tom Cruise', 'actor:Scarlett Johansson'],
]
);
```
</TabItem>
</Tabs>
30 changes: 29 additions & 1 deletion website/docs/api-clients/guides/retrieving-facets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ For example, you can retrieve your books' facets with the `search` method, and t
groupId="language"
defaultValue="js"
values={[
{ label: 'JavaScript', value: 'js', }
{ label: 'JavaScript', value: 'js', },
{ label: 'JavaScript', value: 'js', },
{ label: 'PHP', value: 'php', }
]
}>
<TabItem value="js">
Expand All @@ -42,5 +44,31 @@ await client.search({
});
```

</TabItem>

<TabItem value="php">

```php
$client->search(
'<YOUR_INDEX_NAME>',
[
'query' => '<YOUR_QUERY>',
'facets' => ['author', 'genre'],
]
);
```

To extract all facet information, you can use a wildcard (`*`).

```php
$client->search(
'<YOUR_INDEX_NAME>',
[
'query' => '<YOUR_QUERY>',
'facets' => ['*'],
]
);
```

</TabItem>
</Tabs>
47 changes: 43 additions & 4 deletions website/docs/api-clients/guides/send-data-to-algolia.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ To push data to Algolia, you need an Application ID and a valid API key with the
groupId="language"
defaultValue="js"
values={[
{ label: 'JavaScript', value: 'js', }
{ label: 'JavaScript', value: 'js', },
{ label: 'PHP', value: 'php', }
]
}>
<TabItem value="js">
Expand All @@ -36,6 +37,16 @@ import { algoliasearch } from '@experimental-api-clients-automation/algoliasearc
const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');
```

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

```php
<?php
$client = Algolia\AlgoliaSearch\Api\SearchClient::create(
'<YOUR_APP_ID>',
'<YOUR_API_KEY>'
);
```
</TabItem>
</Tabs>

Expand All @@ -47,19 +58,47 @@ Before sending anything to Algolia, you need to retrieve your data. You can do t
groupId="language"
defaultValue="js"
values={[
{ label: 'JavaScript', value: 'js', }
{ label: 'JavaScript', value: 'js', },
{ label: 'PHP', value: 'php', }
]
}>
<TabItem value="js">

```js
const records = [{ name: 'Tom Cruise' }, { name: 'Scarlett Johansson' }];
const record1 = { name: 'Tom Cruise' };
const record2 = { name: 'Scarlett Johansson' };

client.saveObject({
indexName: '<YOUR_INDEX_NAME>',
// Accepts a free form `Record<string, any>` object.
body: records,
body: record1,
});

client.saveObject({
indexName: '<YOUR_INDEX_NAME>',
// Accepts a free form `Record<string, any>` object.
body: record2,
});

```

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

```php
$record1 = ['name' => 'Tom Cruise'];
$record2 = ['name' => 'Scarlett Johansson'];

$client->saveObject(
'<YOUR_INDEX_NAME>',
$record1
);

$client->saveObject(
'<YOUR_INDEX_NAME>',
$record2
);

```

</TabItem>
Expand Down
1 change: 1 addition & 0 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ function getSpecsForNavBar() {
prism: {
theme: lightCodeTheme,
darkTheme: darkCodeTheme,
additionalLanguages: ['java', 'php'],
},
}),
}
Expand Down