PHP code example of makina-corpus / nucliadb-php-client

1. Go to this page and download the library: Download makina-corpus/nucliadb-php-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

makina-corpus / nucliadb-php-client example snippets


use Nuclia\ApiClient;

$token = '<your-nucliadb-token>';
$kbid = '<your-nucliadb-knoledgebox-id>';
$zone = '<your-nucliadb-zone>'; //Such as 'europe-1'

$apiClient = new ApiClient($zone, $token, $kbid);

$searchApi = $apiClient->createSearchApi();

use Nuclia\Query\SearchQuery;

$response = $searchApi->search((new SearchQuery())->setQuery('you+shall+not+pass'));

$resourcesApi = $apiClient->createResourcesApi();

use Nuclia\Query\GetResourceQuery;

$rid = '<resource-id>'
$response = $resourcesApi->getResource($rid,(new GetResourceQuery()
    ->setShow(EnumArray::show([ShowEnum::VALUES, ShowEnum::BASIC]))
);

$response = $resourcesApi->createResource([
  'title' =>  'The Fellowship of the Ring',
  'links' => [
    'link-1' => [
      'uri' => 'https://en.wikipedia.org/wiki/The_Lord_of_the_Rings:_The_Fellowship_of_the_Ring'
    ]
  ]
]);

$rid = '<resource-id>'
$response = $resourcesApi->modifyResource(
  $rid,
  [
  'title' =>  'The Fellowship of the Ring (Updated)',
  'links' => [
    'link-1' => [
      'uri' => 'https://www.rottentomatoes.com/m/the_lord_of_the_rings_the_fellowship_of_the_ring'
    ]
  ]
]);

$rid = '<resource-id>'
$resourcesApi->deleteResource($rid);

$resourceFieldsApi = $apiClient->createResourceFieldsApi();

$body = file_get_contents('The-Fellowship-Of-The-Ring.jpg', 'r');
$md5 = md5($body);
$rid = '<resource-id>'
$fieldId = '<field-id>' // A free string used to identify your file field in resource.

$response = $resourceFieldsApi->uploadBinaryFile($rid, $fieldId, $body, (new UploadBinaryFileHeaders())->setMd5($md5));