<?php require 'vendor/autoload.php'; use Sajari\Engine\EngineClient; use Sajari\Engine\Exception\EngineException; $logger = new Monolog\Logger('log'); $logger->pushHandler(new Monolog\Handler\StreamHandler('php://stdout')); $c = new EngineClient(new Guzzle\Http\Client(), array('access_key' => getenv('SAJARI_ACCESS_KEY'), 'secret_key' => getenv('SAJARI_SECRET_KEY'), 'company' => getenv('SAJARI_COMPANY'), 'collection' => getenv('SAJARI_COLLECTION')), $logger); try { $r = $c->add(array('meta' => array('id' => '123', 'field' => 'the field value'))); echo var_export($r, true), PHP_EOL; } catch (EngineException $e) { echo 'There was an error adding the document. ', $e->getMessage(), PHP_EOL; } try { $r = $c->remove(array('meta' => array('id' => '123'))); echo var_export($r, true), PHP_EOL; } catch (EngineException $e) { echo 'There was an error removing the document. ', $e->getMessage(), PHP_EOL; }
<?php require 'vendor/autoload.php'; use Sajari\Engine\EngineClient; use Sajari\Engine\Exception\EngineException; $c = new EngineClient(new Guzzle\Http\Client(), array('access_key' => getenv('SAJARI_ACCESS_KEY'), 'secret_key' => getenv('SAJARI_SECRET_KEY'), 'company' => getenv('SAJARI_COMPANY'), 'collection' => getenv('SAJARI_COLLECTION'))); try { $r = $c->add(array('q' => implode(' ', array(getenv('FIRST_NAME'), getenv('LAST_NAME'))), 'meta' => array('first_name' => getenv('FIRST_NAME'), 'last_name' => getenv('LAST_NAME')))); echo var_export($r, true), PHP_EOL; } catch (EngineException $e) { echo 'There was an error adding the document. ', $e->getMessage(), PHP_EOL; }
/** * @dataProvider emptyResponseDataProvider */ public function testAddWhenResponseIsEmpty($emptyResponse) { $this->clientMocker->addResponse(new Response(200, null, $emptyResponse)); $this->engineClient->add('dummy_input_data'); }
<?php require 'vendor/autoload.php'; use Sajari\Engine\EngineClient; use Sajari\Engine\Exception\EngineException; $c = new EngineClient(new Guzzle\Http\Client(), array('access_key' => getenv('SAJARI_ACCESS_KEY'), 'secret_key' => getenv('SAJARI_SECRET_KEY'), 'company' => getenv('SAJARI_COMPANY'), 'collection' => getenv('SAJARI_COLLECTION'))); try { $r = $c->add(array('q' => implode(' ', array(getenv('FIRST_NAME'), getenv('LAST_NAME'))), 'meta' => array('first_name' => getenv('FIRST_NAME'), 'last_name' => getenv('LAST_NAME'), 'some' => array('array', 'values', 'here')))); echo var_export($r, true), PHP_EOL; } catch (EngineException $e) { echo 'There was an error adding the document. ', $e->getMessage(), PHP_EOL; }