当前位置: 首页>>代码示例>>PHP>>正文


PHP Index::exists方法代码示例

本文整理汇总了PHP中Elastica\Index::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Index::exists方法的具体用法?PHP Index::exists怎么用?PHP Index::exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Elastica\Index的用法示例。


在下文中一共展示了Index::exists方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getIndex

 /**
  * @return Index
  */
 private function getIndex()
 {
     if (null === $this->index) {
         $this->index = $this->client->getIndex($this->indexName);
         if (!$this->index->exists()) {
             $this->index->create();
         }
     }
     return $this->index;
 }
开发者ID:basster,项目名称:doctrine-elastica-cache,代码行数:13,代码来源:Cache.php

示例2: backupAction

 /**
  * @actionInfo(name='Бэкап данных')
  */
 public function backupAction()
 {
     $this->folderName = __DIR__ . '/backup/';
     if (!$this->elasticaIndex->exists()) {
         $this->log->error('Индекс для бэкапа отсутствует: {indexName}', ['indexName' => $this->indexName]);
         return;
     }
     $this->checkFileName();
     $this->checkBackupFolder();
     $this->log->info('Всё ок, бекапим {indexName} в {fileName}', ['indexName' => $this->indexName, 'fileName' => $this->fileName]);
     $this->log->info('Параметры бэкапа: sizePerShard={sizePerShard}', ['sizePerShard' => $this->sizePerShard]);
     $scanAndScroll = $this->getScanAndScroll();
     foreach ($scanAndScroll as $resultSet) {
         $buffer = [];
         /* @var \Elastica\ResultSet $resultSet */
         $results = $resultSet->getResults();
         foreach ($results as $result) {
             $item = [];
             $item['_id'] = $result->getId();
             $item['_source'] = $result->getSource();
             $buffer[] = json_encode($item, JSON_UNESCAPED_UNICODE);
         }
         $fileBody = implode(PHP_EOL, $buffer);
         if (file_put_contents($this->fileName, $fileBody, FILE_APPEND)) {
             $countDocuments = count($results);
             $this->log->info('Сохранили {countDocuments} записей', ['countDocuments' => $countDocuments]);
         } else {
             $this->log->error('Ошибка записи данных');
             die;
         }
     }
 }
开发者ID:mzf,项目名称:phalcon-php-elasticsearch-backup,代码行数:35,代码来源:elasticsearch-dumper.php

示例3: validate

 /**
  * @return Status
  */
 public function validate()
 {
     if ($this->startOver) {
         $this->outputIndented("Blowing away index to start over...");
         $this->createIndex(true);
         $this->output("ok\n");
         return Status::newGood();
     }
     if (!$this->index->exists()) {
         $this->outputIndented("Creating index...");
         $this->createIndex(false);
         $this->output("ok\n");
         return Status::newGood();
     }
     $this->outputIndented("Index exists so validating...\n");
     return Status::newGood();
 }
开发者ID:zoglun,项目名称:mediawiki-extensions-CirrusSearch,代码行数:20,代码来源:IndexValidator.php

示例4: initialize

 /**
  * Initialize the ElasticSearch client, and setup settings for the client.
  * 
  * @return void
  */
 public function initialize()
 {
     spl_autoload_register(array($this, 'autoLoad'));
     $this->_connectionOptions = array('url' => $this->modx->getOption('sisea.elastic.hostname', null, 'http://127.0.0.1') . ':' . $this->modx->getOption('sisea.elastic.port', null, 9200) . '/');
     try {
         $this->client = new \Elastica\Client($this->_connectionOptions);
         $this->index = $this->client->getIndex(strtolower($this->modx->getOption('sisea.elastic.index', null, 'siplesearchindex')));
         if (!$this->index->exists()) {
             $indexSetup = $this->modx->getObject('modSnippet', array('name' => 'SimpleSearchElasticIndexSetup'));
             if ($indexSetup) {
                 $indexOptions = $this->modx->fromJSON($this->modx->runSnippet('SimpleSearchElasticIndexSetup'));
             } else {
                 $indexOptions = $this->modx->fromJSON($this->modx->runSnippet('SimpleSearchElasticIndexSetup_default'));
             }
             $this->index->create($indexOptions, true);
         }
     } catch (Exception $e) {
         $this->modx->log(xPDO::LOG_LEVEL_ERROR, 'Error connecting to ElasticSearch server: ' . $e->getMessage());
     }
 }
开发者ID:raadhuis,项目名称:modx-basic,代码行数:25,代码来源:simplesearchdriverelastic.class.php

示例5: setUp

 protected function setUp()
 {
     $typeName = Cache::TYPE_NAME;
     $this->type = $this->prophesize('\\Elastica\\Type');
     $this->type->request(Argument::any(), Argument::cetera())->willReturn(true);
     $this->type->getName()->willReturn($typeName);
     $this->index = $this->prophesize('\\Elastica\\Index');
     $this->index->getType($typeName)->willReturn($this->type->reveal());
     $this->index->exists()->willReturn(true);
     $nsDoc = new Document('DoctrineNamespaceCacheKey[]', [Cache::VALUE_FIELD => serialize($this->namespaceId)]);
     $this->type->getIndex()->willReturn($this->index->reveal());
     $this->type->getDocument("DoctrineNamespaceCacheKey[]")->willReturn($nsDoc);
     $this->client = $this->prophesize('\\Elastica\\Client');
     $this->client->getIndex($this->indexName)->willReturn($this->index->reveal());
     $this->cache = new Cache($this->client->reveal(), ['index' => $this->indexName]);
 }
开发者ID:basster,项目名称:doctrine-elastica-cache,代码行数:16,代码来源:CacheTest.php

示例6: deleteIndex

 /**
  * Удаление индекса
  */
 public function deleteIndex()
 {
     if ($this->index->exists()) {
         $this->index->delete();
     }
 }
开发者ID:anmoroz,项目名称:yii2-analytics,代码行数:9,代码来源:ElasticaBase.php

示例7: setUp

 protected function setUp()
 {
     /** @var ElasticaService elasticaService */
     $elasticaService = $this->getContainer()->get("revinate_search.elasticsearch_service");
     $this->elasticaClient = $elasticaService->getInstance();
     $this->index = new \Elastica\Index($this->elasticaClient, View::INDEX_NAME);
     if (!$this->index->exists()) {
         $this->index->create(array("index.number_of_replicas" => "0", "index.number_of_shards" => "1"));
         $this->type = new \Elastica\Type($this->index, View::INDEX_TYPE);
         $mappingJson = json_decode(file_get_contents(__DIR__ . "/../data/es/mapping.json"), true);
         $mapping = new \Elastica\Type\Mapping($this->type, $mappingJson['properties']);
         $this->type->setMapping($mapping);
     } else {
         $this->type = new \Elastica\Type($this->index, View::INDEX_TYPE);
     }
     $this->timeSeriesIndex = new \Elastica\Index($this->elasticaClient, StatusLog::INDEX_NAME . self::$timeSeriesTestDateSuffix);
     if (!$this->timeSeriesIndex->exists()) {
         $this->timeSeriesIndex->create(array("index.number_of_replicas" => "0", "index.number_of_shards" => "1"));
         $this->timeSeriesType = new \Elastica\Type($this->timeSeriesIndex, StatusLog::INDEX_TYPE);
         $mappingJson = json_decode(file_get_contents(__DIR__ . "/../data/es/statusLogMapping.json"), true);
         $mapping = new \Elastica\Type\Mapping($this->timeSeriesType, $mappingJson['properties']);
         $this->timeSeriesType->setMapping($mapping);
     } else {
         $this->timeSeriesType = new \Elastica\Type($this->timeSeriesIndex, StatusLog::INDEX_TYPE);
     }
 }
开发者ID:revinate,项目名称:search-bundle,代码行数:26,代码来源:BaseTestCase.php


注:本文中的Elastica\Index::exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。