定制 hlquery/php-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hlquery/php-client

Composer 安装命令:

composer require hlquery/php-client

包简介

PHP client library for hlquery search engine

README 文档

README

hlquery logo

A modular PHP client library for hlquery, designed with a familiar and intuitive API structure.

Follow hlquery Commit Activity GitHub hlquery License

What is the hlquery PHP API?

The hlquery PHP API is the official PHP client for hlquery. It gives PHP applications a straightforward way to talk to the search engine through a small client instead of manually assembling curl calls and JSON payloads.

The library wraps hlquery's HTTP endpoints in a service-based API so you can create collections, index documents, run searches, manage lexical resources, query SAM, and call custom module routes from normal PHP code.

Why use it?

Use the PHP API when you want hlquery integration to feel like part of your application instead of a pile of hand-written REST calls. It reduces boilerplate, keeps authentication and request formatting consistent, and makes common operations easier to read and maintain.

Why choose it over raw HTTP?

Choose the PHP client over raw HTTP when you want less boilerplate around search, indexing, and admin operations, one consistent client for auth, params, headers, and response parsing, and direct access to collections, documents, SQL, overrides, synonyms, stopwords, and SAM. It also works in plain PHP with no framework requirement.

Install

Requirements:

  • PHP >= 7.0
  • ext-curl
  • ext-json

Composer:

composer require hlquery/php-client

Local usage:

require_once __DIR__ . '/lib/autoload.php';

use Hlquery\Client;
$client = new Client(getenv('HLQ_BASE_URL') ?: (getenv('HLQUERY_BASE_URL') ?: 'http://localhost:9200'));

Composer usage:

require_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',
]);

$client->setAuthToken('your_token_here', 'bearer');
$client->setAuthToken('your_api_key_here', 'api-key');

Quick Start

require_once __DIR__ . '/vendor/autoload.php';

use Hlquery\Client;

$client = new Client('http://localhost:9200');

$health = $client->health();
if ($health->isSuccess()) {
    echo "status: " . (($health->getBody()['status'] ?? 'ok')) . PHP_EOL;
}

$collections = $client->listCollections(0, 10);
print_r($collections->getBody());

Collections

List collections with pagination and iterate over the result:

$response = $client->listCollections(0, 100);

if (!$response->isSuccess()) {
    throw new RuntimeException('Failed to list collections: ' . $response->getStatusCode());
}

$body = $response->getBody();
$collections = $body['collections'] ?? [];

foreach ($collections as $collection) {
    $name = is_array($collection) ? ($collection['name'] ?? '') : $collection;

    if ($name === '') {
        continue;
    }

    echo $name . PHP_EOL;
}

SAM

The PHP client exposes all current SAM endpoints through Client::sam():

  • search($collectionName, $query, $params = []) calls GET /sam/search.
  • status($collectionName = null, $params = []) calls GET /sam/status.
  • history($collectionName = null, $limit = 100, $params = []) calls GET /sam/history.

Use the SAM service for search, background status, and recent query history:

SAM is separate from vector search. It performs term and intent-style lookup, not vector similarity search.

$sam = $client->sam();

$status = $sam->status('music');
$history = $sam->history('music', 5);
$results = $sam->search('music', 'queen of pop', [
    'limit' => 10,
]);

print_r($status->getBody());
print_r($history->getBody());
print_r($results->getBody());

SQL

$sql = $client->sql();

$rows = $sql->query('SHOW COLLECTIONS;');
$books = $sql->search(
    'books',
    'SELECT id, title FROM books ORDER BY title ASC LIMIT 3;'
);

print_r($rows->getBody());
print_r($books->getBody());

Reduce Text Example

Use executeRequest() to call custom module routes directly:

$moduleResponse = $client->executeRequest('GET', '/modules/<name>/<route>', null, [
    'q' => 'example query',
]);

print_r($moduleResponse->getBody());

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-04-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固