本文整理汇总了PHP中Elastica\Client类的典型用法代码示例。如果您正苦于以下问题:PHP Client类的具体用法?PHP Client怎么用?PHP Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: publish
public function publish(Client $client, $actionType, TableInterface $table, RecordInterface $record)
{
$con = new Condition(array('id', '=', $record->id));
$row = $table->getRow(array('id', 'pageId', 'userId', 'urlTitle', 'title', 'text'), $con);
$index = $client->getIndex('amun');
$type = $index->getType('page');
$id = $row['pageId'] . '-' . $record->id;
try {
$document = $type->getDocument($id);
if ($actionType == RecordAbstract::INSERT || $actionType == RecordAbstract::UPDATE) {
// get referring page
$handler = $this->hm->getHandler('AmunService\\Content\\Page');
$page = $handler->get($row['pageId'], array('id', 'path', 'urlTitle', 'title'));
$data = array('id' => $id, 'userId' => $row['userId'], 'path' => $page['path'] . '/view/' . $row['id'] . '/' . $row['urlTitle'], 'title' => $row['title'], 'content' => $row['text'], 'date' => time());
$type->updateDocument(new Document($id, $data));
} else {
if ($actionType == RecordAbstract::DELETE) {
$type->deleteDocument($document);
}
}
} catch (NotFoundException $e) {
if ($actionType == RecordAbstract::INSERT || $actionType == RecordAbstract::UPDATE) {
// get referring page
$handler = $this->hm->getHandler('AmunService\\Content\\Page');
$page = $handler->get($row['pageId'], array('id', 'path', 'urlTitle', 'title'));
$data = array('id' => $id, 'userId' => $row['userId'], 'path' => $page['path'] . '/view/' . $row['id'] . '/' . $row['urlTitle'], 'title' => $row['title'], 'content' => $row['text'], 'date' => time());
$type->addDocument(new Document($id, $data));
} else {
if ($actionType == RecordAbstract::DELETE) {
// is already deleted
}
}
}
$type->getIndex()->refresh();
}
开发者ID:visapi,项目名称:amun,代码行数:35,代码来源:SearchIndexer.php
示例2: testShutdown
/**
* Shuts one of two nodes down (if two available)
*/
public function testShutdown()
{
$client = $this->_getClient();
$nodes = $client->getCluster()->getNodes();
$count = count($nodes);
if ($count < 2) {
$this->markTestSkipped('At least two nodes have to be running, because 1 node is shutdown');
}
// Store node info of node with port 9200 for later
foreach ($nodes as $key => $node) {
if ($node->getInfo()->getPort() == 9200) {
$info = $node->getInfo();
unset($nodes[$key]);
}
}
// Select one of the not port 9200 nodes and shut it down
$node = array_shift($nodes);
$node->shutdown('2s');
// Wait until node is shutdown
sleep(5);
// Use still existing node
$client = new Client(array('host' => $info->getIp(), 'port' => $info->getPort()));
$names = $client->getCluster()->getNodeNames();
// One node less ...
$this->assertEquals($count - 1, count($names));
}
开发者ID:kskod,项目名称:Elastica,代码行数:29,代码来源:NodeTest.php
示例3: requestByType
/**
* Making a request by giving in raw json as the query
* @param jsonstring $query Raw json query
* @return array An array containing the mapped entities.
*/
public function requestByType($query, $type = 'organisation,vacancy,person', $requestType = Request::GET)
{
$client = new Client(array('host' => $this->es_host, 'port' => $this->es_port));
$path = $this->getIndex() . '/' . $type . '/_search';
$response = $client->request($path, $requestType, $query)->getData();
return $this->esMapper->getEntities($response['hits']['hits']);
}
开发者ID:howest-wsde,项目名称:VrijwilligersTool,代码行数:12,代码来源:ElasticsearchQuery.php
示例4: initialize
/**
* До любых других действий
*/
public function initialize()
{
$currentActionName = $this->dispatcher->getActiveMethod();
$annotations = $this->annotations->getMethod(self::class, $currentActionName);
if ($annotations->has('actionInfo')) {
$annotation = $annotations->get('actionInfo');
$actionTitle = $annotation->getNamedArgument('name');
$this->log->info('Запустили: {actionTitle}', ['actionTitle' => $actionTitle]);
} else {
$currentTaskName = $this->dispatcher->getTaskName();
$this->log->info('Запустили: {currentTaskName}::{currentActionName}', ['currentTaskName' => $currentTaskName, 'currentActionName' => $currentActionName]);
}
$this->indexName = $this->dispatcher->getParam('index', 'string', false);
$this->typeName = $this->dispatcher->getParam('type', 'string', false);
if (!$this->indexName) {
$this->log->error('Указание индекса является обязательным параметром');
die;
}
$this->sizePerShard = $this->dispatcher->getParam('sizePerShard', 'int', false) ?: $this->sizePerShard;
$this->elasticsearchHost = $this->dispatcher->getParam('host', 'string', false) ?: $this->elasticsearchHost;
$this->elasticsearchPort = $this->dispatcher->getParam('port', 'int', false) ?: $this->elasticsearchPort;
$connectParams = ['host' => $this->elasticsearchHost, 'port' => $this->elasticsearchPort];
$this->client = new Client($connectParams);
try {
$this->client->getStatus();
} catch (\Elastica\Exception\Connection\HttpException $e) {
$context = ['host' => $this->elasticsearchHost, 'port' => $this->elasticsearchPort];
$this->log->error('Подключение к серверу elasticsearch отсутствует: http://{host}:{port}', $context);
die;
}
$this->elasticaIndex = $this->client->getIndex($this->indexName);
$this->elasticaType = $this->elasticaIndex->getType($this->typeName);
}
开发者ID:mzf,项目名称:phalcon-php-elasticsearch-backup,代码行数:36,代码来源:elasticsearch-dumper.php
示例5: testDeleteIndex
public function testDeleteIndex()
{
$index = $this->getMockBuilder('Elastica\\Index')->disableOriginalConstructor()->setMethods(array('delete'))->getMock();
$index->expects($this->once())->method('delete');
$this->elasticaClient->expects($this->once())->method('getIndex')->with('comments')->will($this->returnValue($index));
$this->client->deleteIndex('comments');
}
开发者ID:revinate,项目名称:search-bundle,代码行数:7,代码来源:ClientTest.php
示例6: handle
/**
* Handle index creation command
*
* @param Client $client
* @param string $index
* @param string $alias
*/
public function handle(Client $client, $index, $alias)
{
$config = $this->configurations->get($alias);
if (null === $config) {
throw new \InvalidArgumentException();
}
$client->getIndex($index)->create($config);
}
开发者ID:gbprod,项目名称:elastica-extra-bundle,代码行数:15,代码来源:CreateIndexHandler.php
示例7: addDocumentsToPlayListIndex
/**
* @param $documents
*/
protected function addDocumentsToPlayListIndex($documents)
{
$elasticaClient = new Client();
$playListIndex = $elasticaClient->getIndex('track_index');
$trackType = $playListIndex->getType('track');
$trackType->addDocuments($documents);
$trackType->getIndex()->refresh();
}
开发者ID:slaparra,项目名称:Training-Elastic-Search-Symfony,代码行数:11,代码来源:ImportTracksFromDbToTrackIndexCommand.php
示例8: handle
/**
* Handle index creation command
*
* @param Client $client
* @param string $index
* @param string $type
* @param string $alias
*/
public function handle(Client $client, $index, $type, $alias)
{
$mapping = $this->configurations->getMapping($alias, $type);
if (!$mapping) {
throw new \InvalidArgumentException();
}
$client->getIndex($index)->getType($type)->setMapping($mapping);
}
开发者ID:gbprod,项目名称:elastica-extra-bundle,代码行数:16,代码来源:PutIndexMappingsHandler.php
示例9: handle
/**
* Handle index creation command
*
* @param Client $client
* @param string $index
* @param string $alias
*/
public function handle(Client $client, $index, $alias)
{
$settings = $this->configurations->getSettings($alias);
if (null === $settings) {
throw new \InvalidArgumentException();
}
$client->getIndex($index)->setSettings($settings);
}
开发者ID:gbprod,项目名称:elastica-extra-bundle,代码行数:15,代码来源:PutIndexSettingsHandler.php
示例10: handle
/**
* Handle index deletion command
*
* @param Client $client
* @param string $index
*
* @throws IndexNotFoundException
*/
public function handle(Client $client, $index)
{
$index = $client->getIndex($index);
if (!$index->exists()) {
throw new IndexNotFoundException($index);
}
$index->delete();
}
开发者ID:gbprod,项目名称:elastica-extra-bundle,代码行数:16,代码来源:DeleteIndexHandler.php
示例11: __construct
/**
* @param array $options
*/
public function __construct($options = [])
{
parent::__construct($options);
$this->client = new Client($options);
if (!isset($options['index'])) {
$options['index'] = 'log';
}
$this->index = $this->client->getIndex($options['index']);
}
开发者ID:hayloft,项目名称:zend-log-elastic,代码行数:12,代码来源:Elastic.php
示例12: persist
/**
* @param array $payload
*
* @return bool
*/
public function persist(array $payload)
{
$documents = array_map(function (array $user) {
return $this->makeDocument($user);
}, $payload);
$responseSet = $this->elasticaClient->getIndex($this->target->index)->addDocuments($documents);
$this->responses = $responseSet;
return true;
}
开发者ID:jiangyu7408,项目名称:notification,代码行数:14,代码来源:GatewayUserPersist.php
示例13: __construct
/**
* Constructor
*
* @param Client $client The elastic search client.
* @param string $indexName The elastic search index name.
* @param boolean $delete Delete the index if already exist (default = false).
*/
public function __construct(Client $client, $indexName, $delete = false)
{
$this->client = $client;
$this->index = $client->getIndex($indexName);
// Checks if the given index is already created
if (!$this->index->exists($indexName)) {
// Create the index.
$this->index->create(array(), $delete);
}
}
开发者ID:Tessi-Tms,项目名称:TmsDataLimitNamespaceBundle,代码行数:17,代码来源:ElasticSearchDataProvider.php
示例14: testBasicGettingStarted
public function testBasicGettingStarted()
{
$client = new \Elastica\Client();
$index = $client->getIndex('ruflin');
$type = $index->getType('users');
$id = 2;
$data = array('firstname' => 'Nicolas', 'lastname' => 'Ruflin');
$doc = new \Elastica\Document($id, $data);
$type->addDocument($doc);
}
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:10,代码来源:ExampleTest.php
示例15: testInvalidElasticRequest
/**
* @expectedException \Elastica\Exception\ResponseException
*/
public function testInvalidElasticRequest()
{
$connection = new Connection();
$connection->setHost('localhost');
$connection->setPort(9500);
$connection->setTransport('Thrift');
$client = new Client();
$client->addConnection($connection);
$index = new Index($client, 'missing_index');
$index->getStatus();
}
开发者ID:kskod,项目名称:Elastica,代码行数:14,代码来源:ThriftTest.php
示例16: postInstall
public function postInstall(RecordInterface $record)
{
$client = new Client(array('host' => $this->registry['search.host'], 'port' => $this->registry['search.port']));
$index = $client->getIndex('amun');
$index->create();
$type = $index->getType('page');
$mapping = new Mapping();
$mapping->setType($type);
$mapping->setProperties(array('id' => array('type' => 'string', 'include_in_all' => false), 'userId' => array('type' => 'integer', 'include_in_all' => false), 'path' => array('type' => 'string', 'include_in_all' => true), 'title' => array('type' => 'string', 'include_in_all' => true), 'content' => array('type' => 'string', 'include_in_all' => true), 'date' => array('type' => 'date', 'include_in_all' => false)));
$mapping->send();
}
开发者ID:visapi,项目名称:amun,代码行数:11,代码来源:Setup.php
示例17: setUpBeforeClass
public static function setUpBeforeClass()
{
$host = getenv('ELASTIC_HOST');
$port = getenv('ELASTIC_PORT') ?: 9200;
$indexName = getenv('ELASTIC_INDEX') ?: 'pbj_tests';
if (empty($host) || empty($port)) {
return;
}
$client = new Client(['connections' => [['host' => $host, 'port' => $port]]]);
self::$index = $client->getIndex($indexName);
self::createIndex();
}
开发者ID:gdbots,项目名称:pbj-php,代码行数:12,代码来源:ElasticaTest.php
示例18: createIndex
/**
* @param \Generated\Shared\Transfer\ElasticsearchIndexDefinitionTransfer $indexDefinitionTransfer
*
* @return void
*/
protected function createIndex(ElasticsearchIndexDefinitionTransfer $indexDefinitionTransfer)
{
$index = $this->elasticaClient->getIndex($indexDefinitionTransfer->getIndexName());
if (!$index->exists()) {
$this->messenger->info(sprintf('Creating elasticsearch index: "%s"', $indexDefinitionTransfer->getIndexName()));
$settings = $indexDefinitionTransfer->getSettings();
$index->create($settings);
}
foreach ($indexDefinitionTransfer->getMappings() as $mappingName => $mappingData) {
$this->sendMapping($index, $mappingName, $mappingData);
}
}
开发者ID:spryker,项目名称:Search,代码行数:17,代码来源:IndexInstaller.php
示例19: testWithNoValidConnection
public function testWithNoValidConnection()
{
$connections = array(new \Elastica\Connection(array('host' => '255.255.255.0', 'timeout' => 2)), new \Elastica\Connection(array('host' => '45.45.45.45', 'port' => '80', 'timeout' => 2)), new \Elastica\Connection(array('host' => '10.123.213.123', 'timeout' => 2)));
$count = 0;
$client = new Client(array(), function () use(&$count) {
++$count;
});
$client->setConnections($connections);
try {
$client->request('/_aliases');
$this->fail('Should throw exception as no connection valid');
} catch (\Elastica\Exception\ConnectionException $e) {
$this->assertEquals(count($connections), $count);
}
}
开发者ID:tkaven,项目名称:Elastica,代码行数:15,代码来源:SimpleTest.php
示例20: __construct
public function __construct($options, $indexName, $typeName)
{
if ($this->client) {
return $this->client;
}
if ($options['debug']) {
define('DEBUG', true);
}
$this->host = $options['host'];
$this->port = $options['port'];
$this->client = new \Elastica\Client(['host' => $this->host, 'port' => $this->port]);
$this->index = $this->client->getIndex($indexName);
$this->indexName = $indexName;
$this->typeName = $typeName;
}
开发者ID:anmoroz,项目名称:yii2-analytics,代码行数:15,代码来源:ElasticaBase.php
注:本文中的Elastica\Client类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论