A modular PHP client library for hlquery, designed with a familiar and intuitive API structure.
Compact PHP client for hlquery. No framework required, no extra runtime dependencies beyond curl and json.
Included in the current client:
- Collections
- Documents
- Search
- Keys
- Aliases
- Overrides
- Synonyms
- Stopwords
- System helpers, including
etc()
Requirements:
- PHP
>= 7.0 ext-curlext-json
Local usage:
require_once __DIR__ . '/lib/autoload.php';
use Hlquery\Client;
$client = new Client('http://localhost:9200');Composer:
composer require hlquery/php-clientrequire_once __DIR__ . '/vendor/autoload.php';
use Hlquery\Client;
$client = new Client('http://localhost:9200');Auth:
$client = new Client('http://localhost:9200', [
'token' => 'your_token_here',
'auth_method' => 'bearer', // or 'api-key'
]);
// or later
$client->setAuthToken('your_token_here', 'bearer');require_once __DIR__ . '/lib/autoload.php';
use Hlquery\Client;
$client = new Client('http://localhost:9200');
$health = $client->health();
if ($health->isSuccess()) {
$body = $health->getBody();
echo "status: " . ($body['status'] ?? 'ok') . PHP_EOL;
}
$collections = $client->listCollections(0, 10);
print_r($collections->getBody());If the ai_search module is enabled, use executeRequest() to summarize a stored document:
$summary = $client->executeRequest('GET', '/modules/ai_search/talk', null, [
'q' => 'summarize onboarding guide in docs',
'run' => 'true',
]);
print_r($summary->getBody());$schema = [
'searchable_fields' => ['title', 'description'],
'filterable_fields' => ['category', 'in_stock'],
'sortable_fields' => ['price', 'rating'],
];
$res = $client->collections()->create('products', $schema);
print_r($res->getBody());$client->documents()->add('products', [
'id' => 'sku-1',
'title' => 'Trail Running Shoes',
'description' => 'Lightweight shoes for mixed terrain',
'category' => 'footwear',
'price' => 129,
'rating' => 4.7,
'in_stock' => true,
]);
$client->documents()->import('products', [
[
'id' => 'sku-2',
'title' => 'Waterproof Jacket',
'description' => 'Breathable shell for wet weather',
'category' => 'outerwear',
'price' => 189,
],
[
'id' => 'sku-3',
'title' => 'Daypack 20L',
'description' => 'Compact pack for short hikes',
'category' => 'bags',
'price' => 79,
],
]);If q is set and query_by is omitted, the client tries to use the collection's searchable_fields.
$results = $client->search('products', [
'q' => 'waterproof jacket',
'limit' => 10,
]);$results = $client->searchApi()->multiSearch([
[
'collection' => 'products',
'q' => 'running',
'query_by' => 'title,description',
],
[
'collection' => 'products',
'q' => 'backpack',
'query_by' => 'title,description',
],
]);$doc = $client->getDocument('products', 'sku-1');
print_r($doc->getBody());$client->documents()->update('products', 'sku-1', [
'price' => 119,
'in_stock' => false,
]);
$client->documents()->delete('products', 'sku-3');$client->synonyms()->create('products', 'shoe_terms', [
'root' => 'shoe',
'synonyms' => ['sneaker', 'trainer'],
]);
$synonyms = $client->synonyms()->list('products');
print_r($synonyms->getBody());Global synonyms are also supported:
$client->synonyms()->createGlobal('global_shoe_terms', [
'root' => 'shoe',
'synonyms' => ['sneaker', 'trainer'],
]);