lupasearch / lupasearch-php-client
LupaSearch API PHP 客户端
0.5.1
2024-05-08 11:36 UTC
Requires
- php: ^7.2 || ^8.0
- ext-json: *
- guzzlehttp/guzzle: ^6.3 || ^7
README
- 当前客户端版本:v0.5.1
- 支持 PHP ^7.2
入门指南
身份验证和授权
初始化客户端对象并设置 API 密钥进行授权(推荐)。
$client = new \LupaSearch\LupaClient();
$client->setApiKey("your_api_key_here");
或者,您可以使用电子邮件和密码凭据进行身份验证,并使用 JWT 令牌进行授权。
$client = new \LupaSearch\LupaClient();
$client
->setEmail('account@search.com')
->setPassword('password')
->authenticate();
数据索引
将文档导入搜索索引
$indexId = '7a31899f-31bc-46ac-b782-a44d71c5d622';
$documents = [
'documents' => [
[
'id' => 1,
'name' => 'Bag',
'category' => 'Bags'
],
[
'id' => '2',
'name' => 'Glasses',
'price' => 9.99,
'category' => 'Accessories'
]
]
];
$lupaDocumentsApi = new \LupaSearch\Api\DocumentsApi($client);
$importResponse = $lupaDocumentsApi->importDocuments(
$indexId,
$documents
);
跟踪异步任务进度
$lupaTasksApi = new \LupaSearch\Api\TasksApi($client);
$tasks = $lupaTasksApi->getTasks($indexId, [
'batchKey' => $importResponse['batchKey']
]);
搜索
发送搜索请求
$publicQueryKey = 'qraljpj1reo9';
$lupaPublicQueriesApi = new \LupaSearch\Api\PublicQueryApi($client);
$searchResponse = $lupaPublicQueriesApi->search($queryKey, [
'searchText' => '',
'filters' => ['category' => ['Accessories']]
]);