PHP code example of shevabam / meilisearch-light-php-client
1. Go to this page and download the library: Download shevabam/meilisearch-light-php-client library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shevabam / meilisearch-light-php-client example snippets
$host = 'http://xxx.xxx.xxx.xxx:7700';
$searchKey = 'yyy';
$adminKey = 'zzz';
$Request = new MeilisearchLighClient\Request($host);
$params = ['key' => $adminKey];
$Request->call($params, 'GET', 'indexes');
$params = [
'key' => $searchKey,
'headers' => ['Content-type: application/json'],
];
if ($Request->isOk())
{
$Response = $Request->getResponse();
var_dump($Response->get()); // Response content
}
else
{
echo $Request->getHttpStatus();
}
$Response = $Request->getResponse(true);
t = 'http://xxx.xxx.xxx.xxx:7700';
$searchKey = 'yyy';
$adminKey = 'zzz';
$Request = new MeilisearchLightClient\Request($host);
$params = ['key' => $adminKey];
$Request->call($params, 'GET', 'indexes');
$response_content = null;
if ($Request->isOk())
{
$Response = $Request->getResponse(true);
$response_content = $Response->get();
}
else
{
echo $Request->getHttpStatus();
}
echo '<pre>'; print_r($response_content);
t = 'http://xxx.xxx.xxx.xxx:7700';
$searchKey = 'yyy';
$adminKey = 'zzz';
$Request = new MeilisearchLightClient\Request($host);
$params = [
'key' => $adminKey,
'headers' => ['Content-type: application/json'],
];
$Request->call($params, 'POST', 'indexes/movies/documents', '@movies.json');
$response_content = null;
if ($Request->isOk())
{
$Response = $Request->getResponse(true);
$response_content = $Response->get();
}
else
{
echo $Request->getHttpStatus();
}
echo '<pre>'; print_r($response_content);
t = 'http://xxx.xxx.xxx.xxx:7700';
$searchKey = 'yyy';
$adminKey = 'zzz';
$Request = new MeilisearchLightClient\Request($host);
$params = [
'key' => $adminKey,
'headers' => ['Content-type: application/json'],
];
$datas = [
[
'id' => 1,
'title' => 'Sharknado',
],
[
'id' => 2,
'title' => 'Phone Booth',
],
[
'id' => 3,
'title' => 'Jurassic Park',
],
];
$Request->call($params, 'POST', 'indexes/movies/documents', $datas);
$response_content = null;
if ($Request->isOk())
{
$Response = $Request->getResponse(true);
$response_content = $Response->get();
}
else
{
echo $Request->getHttpStatus();
}
echo '<pre>'; print_r($response_content);
t = 'http://xxx.xxx.xxx.xxx:7700';
$searchKey = 'yyy';
$adminKey = 'zzz';
$Request = new MeilisearchLightClient\Request($host);
$params = [
'key' => $searchKey,
'headers' => ['Content-type: application/json'],
];
$Request->call($params, 'POST', 'indexes/movies/search', [
'q' => 'jurassic',
'limit' => 50,
'filter' => 'release_date > '.strtotime(date('2018-01-01')),
]);
$response_content = null;
if ($Request->isOk())
{
$Response = $Request->getResponse(true);
$response_content = $Response->get();
}
else
{
echo $Request->getHttpStatus();
}
echo '<pre>'; print_r($response_content);