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


PHP Document::setId方法代码示例

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


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

示例1: testGetOptions

 public function testGetOptions()
 {
     $document = new Document();
     $document->setIndex('index');
     $document->setOpType('create');
     $document->setParent('2');
     $document->setId(1);
     $options = $document->getOptions(array('index', 'type', 'id', 'parent'));
     $this->assertInternalType('array', $options);
     $this->assertEquals(3, count($options));
     $this->assertArrayHasKey('index', $options);
     $this->assertArrayHasKey('id', $options);
     $this->assertArrayHasKey('parent', $options);
     $this->assertEquals('index', $options['index']);
     $this->assertEquals(1, $options['id']);
     $this->assertEquals('2', $options['parent']);
     $this->assertArrayNotHasKey('type', $options);
     $this->assertArrayNotHasKey('op_type', $options);
     $this->assertArrayNotHasKey('_index', $options);
     $this->assertArrayNotHasKey('_id', $options);
     $this->assertArrayNotHasKey('_parent', $options);
     $options = $document->getOptions(array('parent', 'op_type', 'percolate'), true);
     $this->assertInternalType('array', $options);
     $this->assertEquals(2, count($options));
     $this->assertArrayHasKey('_parent', $options);
     $this->assertArrayHasKey('_op_type', $options);
     $this->assertEquals('2', $options['_parent']);
     $this->assertEquals('create', $options['_op_type']);
     $this->assertArrayNotHasKey('percolate', $options);
     $this->assertArrayNotHasKey('op_type', $options);
     $this->assertArrayNotHasKey('parent', $options);
 }
开发者ID:kskod,项目名称:Elastica,代码行数:32,代码来源:DocumentTest.php

示例2: update

 /**
  * Partial Update
  *
  * @param  string  $docId
  * @param  array    $data
  * @param  integer  $version
  *
  * @throws IndexingException
  *
  * @return null
  */
 public function update($docId, array $data, $version = 1)
 {
     $document = new Document();
     $document->setData($data);
     $document->setId($docId);
     $document->setDocAsUpsert(true);
     try {
         $this->getType($version)->updateDocument($document);
     } catch (\Exception $e) {
         throw new IndexingException('Throw exception while updating', $e->getCode(), $e);
     }
 }
开发者ID:biberlabs,项目名称:zf2-boilerplate,代码行数:23,代码来源:AbstractIndexService.php

示例3: populate

 /**
  * Insert the repository objects in the type index
  *
  * @param \Closure $loggerClosure
  * @param array    $options
  */
 public function populate(\Closure $loggerClosure = null, array $options = array())
 {
     if ($loggerClosure) {
         $loggerClosure('Indexing movies');
     }
     $allMovies = $this->movieManager->getAllMovies();
     $languages = $this->getLanguagesAvailable();
     foreach ($allMovies as $movie) {
         $document = new Document();
         $id = $movie->getId();
         $document->setId($id);
         $titleFr = $this->movieManager->getMovieTitleInLocale($id, $languages['fr']);
         $titleEn = $this->movieManager->getMovieTitleInLocale($id, $languages['en']);
         //            $titleEn = $this->movieManager->getMovieTitleInLocale($id, 'en');
         //            $titleFr = $this->movieManager->getMovieTitleInLocale($id, 'fr');
         $document->setData(array('id' => $id, 'title_fr' => $titleFr['title'], 'title_en' => $titleEn['title']));
         $this->movieType->addDocuments(array($document));
     }
 }
开发者ID:ChristWood,项目名称:videoCollection,代码行数:25,代码来源:TitleProvider.php

示例4: addDocument

 /**
  * Adds the given document to the search index
  *
  * @param  \Elastica\Document $doc Document with data
  * @return \Elastica\Response
  */
 public function addDocument(Document $doc)
 {
     $path = urlencode($doc->getId());
     $type = Request::PUT;
     // If id is empty, POST has to be used to automatically create id
     if (empty($path)) {
         $type = Request::POST;
     }
     $options = $doc->getOptions(array('version', 'version_type', 'routing', 'percolate', 'parent', 'ttl', 'timestamp', 'op_type', 'consistency', 'replication', 'refresh', 'timeout'));
     $response = $this->request($path, $type, $doc->getData(), $options);
     $data = $response->getData();
     // set autogenerated id to document
     if (($doc->isAutoPopulate() || $this->getIndex()->getClient()->getConfigValue(array('document', 'autoPopulate'), false)) && $response->isOk()) {
         if (!$doc->hasId()) {
             if (isset($data['_id'])) {
                 $doc->setId($data['_id']);
             }
         }
         if (isset($data['_version'])) {
             $doc->setVersion($data['_version']);
         }
     }
     return $response;
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:30,代码来源:Type.php


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