lupasearch/lupasearch-php-client

LupaSearch API PHP Client

0.5.1 2024-05-08 11:36 UTC

This package is auto-updated.

Last update: 2024-11-08 13:00:26 UTC


README

  • Current client version: v0.5.1
  • Supports PHP ^7.2

Getting Started

Authentication and authorization

Initiate client object and set the API key for authorization (recommended).

$client = new \LupaSearch\LupaClient();
$client->setApiKey("your_api_key_here");

Alternatively, you can use email and password credentials for authentication and JWT token for authorization.

$client = new \LupaSearch\LupaClient();
$client
    ->setEmail('account@search.com')
    ->setPassword('password')
    ->authenticate();

Data indexing

Import documents into search index:

$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
);

Track progress of asynchronous tasks:

$lupaTasksApi = new \LupaSearch\Api\TasksApi($client);
$tasks = $lupaTasksApi->getTasks($indexId, [
    'batchKey' => $importResponse['batchKey']
]);

Search

Send search request:

$publicQueryKey = 'qraljpj1reo9';
$lupaPublicQueriesApi = new \LupaSearch\Api\PublicQueryApi($client);
$searchResponse = $lupaPublicQueriesApi->search($queryKey, [
    'searchText' => '',
    'filters' => ['category' => ['Accessories']]
]);

Resources