oramacloud/client

v1.0.2 2024-07-19 18:09 UTC

This package is auto-updated.

Last update: 2024-09-07 12:17:21 UTC


README

Package Version PHP Version Tests

使用OramaCloud PHP客户端SDK,您可以在您的Orama索引上执行搜索查询,或通过编程方式更新索引数据并触发新部署。使用REST API将Orama Cloud集成到您的PHP应用程序中,以便在您需要时插入和更新索引数据并触发部署。

安装

composer require oramacloud/client

兼容性

PHP: 7.3或更高版本

与Orama Cloud集成

use OramaCloud\Client;
use OramaCloud\Client\Query;

$client = new Client([
    'api_key' => '<Your Orama Cloud API Key>',
    'endpoint' => '<Your Orama Cloud Endpoint>'
]);

$query = (new Query('red shoes'))
    ->where('price', 'gt', 99.99);

$results = $client->search($query);

高级搜索

use OramaCloud\Client;
use OramaCloud\Client\Query;
use OramaCloud\Client\QueryParams/WhereOperator;
use OramaCloud\Client\QueryParams/SortByOrder;

$client = new Client([
    'api_key' => '<Your Orama Cloud API Key>',
    'endpoint' => '<Your Orama Cloud Endpoint>'
]);

$query = new Query();
$query->term('red shoes')
      ->mode('hybrid')
      ->where('price', WhereOperator::LTE, 9.99)
      ->where('gender', WhereOperator::EQ, 'unisex')
      ->sortBy('price' SortByOrder::DESC)
      ->limit(5)
      ->offset(1);

$results = $client->search($query);

管理您的索引

use OramaCloud\Manager\IndexManager;

$index = new IndexManager('<Your Index-ID>', '<Your Private API Key>');

// Empty data
$index->empty();

// Insert records
$index->insert([
    ['id' => '1', 'name' => 'John Doe', 'age' => 20 ],
    ['id' => '2', 'name' => 'Mario Rossi', 'age' => 25 ],
    ['id' => '3', 'name' => 'John Smith', 'age' => 35 ],
]);

// Update records
$index->update([[ 'id' => '1', 'name' => 'Jane Doe', 'age' => 30 ]]);

// Delete records
$index->delete(['1', '2']);

// Trigger deployment
$index->deploy();

运行测试

composer test

许可证

Apache-2.0许可证。有关更多信息,请参阅许可证文件