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


PHP Document::setParent方法代码示例

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


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

示例1: testParent

 public function testParent()
 {
     $index = $this->_createIndex();
     $typeBlog = new Type($index, 'blog');
     $typeComment = new Type($index, 'comment');
     $mapping = new Mapping();
     $mapping->setParam('_parent', array('type' => 'blog'));
     $typeComment->setMapping($mapping);
     $entry1 = new Document(1);
     $entry1->set('title', 'Hello world');
     $typeBlog->addDocument($entry1);
     $entry2 = new Document(2);
     $entry2->set('title', 'Foo bar');
     $typeBlog->addDocument($entry2);
     $entry3 = new Document(3);
     $entry3->set('title', 'Till dawn');
     $typeBlog->addDocument($entry3);
     $comment = new Document(1);
     $comment->set('author', 'Max');
     $comment->setParent(2);
     // Entry Foo bar
     $typeComment->addDocument($comment);
     $index->optimize();
     $query = new HasChild('Max', 'comment');
     $resultSet = $typeBlog->search($query);
     $this->assertEquals(1, $resultSet->count());
     $this->assertEquals(array('title' => 'Foo bar'), $resultSet->current()->getData());
 }
开发者ID:kskod,项目名称:Elastica,代码行数:28,代码来源:IndexTest.php

示例2: 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

示例3: testHasParent

 /**
  * @group functional
  */
 public function testHasParent()
 {
     $index = $this->_createIndex();
     $shopType = $index->getType('shop');
     $productType = $index->getType('product');
     $mapping = new Mapping();
     $mapping->setParent('shop');
     $productType->setMapping($mapping);
     $shopType->addDocuments(array(new Document('zurich', array('brand' => 'google')), new Document('london', array('brand' => 'apple'))));
     $doc1 = new Document(1, array('device' => 'chromebook'));
     $doc1->setParent('zurich');
     $doc2 = new Document(2, array('device' => 'macmini'));
     $doc2->setParent('london');
     $productType->addDocument($doc1);
     $productType->addDocument($doc2);
     $index->refresh();
     // All documents
     $parentQuery = new HasParent(new MatchAll(), $shopType->getName());
     $search = new Search($index->getClient());
     $results = $search->search($parentQuery);
     $this->assertEquals(2, $results->count());
     $match = new Match();
     $match->setField('brand', 'google');
     $parentQuery = new HasParent($match, $shopType->getName());
     $search = new Search($index->getClient());
     $results = $search->search($parentQuery);
     $this->assertEquals(1, $results->count());
     $result = $results->current();
     $data = $result->getData();
     $this->assertEquals($data['device'], 'chromebook');
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:34,代码来源:HasParentTest.php

示例4: _getTestIndex

 protected function _getTestIndex()
 {
     $index = $this->_createIndex('has_child_test');
     $parentType = $index->getType('parent');
     $childType = $index->getType('child');
     $childMapping = new Mapping($childType);
     $childMapping->setParent('parent');
     $childMapping->send();
     $altType = $index->getType('alt');
     $altDoc = new Document('alt1', array('name' => 'altname'));
     $altType->addDocument($altDoc);
     $parent1 = new Document('parent1', array('id' => 'parent1', 'user' => 'parent1', 'email' => 'parent1@test.com'));
     $parentType->addDocument($parent1);
     $parent2 = new Document('parent2', array('id' => 'parent2', 'user' => 'parent2', 'email' => 'parent2@test.com'));
     $parentType->addDocument($parent2);
     $child1 = new Document('child1', array('id' => 'child1', 'user' => 'child1', 'email' => 'child1@test.com'));
     $child1->setParent('parent1');
     $childType->addDocument($child1);
     $child2 = new Document('child2', array('id' => 'child2', 'user' => 'child2', 'email' => 'child2@test.com'));
     $child2->setParent('parent2');
     $childType->addDocument($child2);
     $child3 = new Document('child3', array('id' => 'child3', 'user' => 'child3', 'email' => 'child3@test.com', 'alt' => array(array('name' => 'testname'))));
     $child3->setParent('parent2');
     $childType->addDocument($child3);
     $index->refresh();
     return $index;
 }
开发者ID:makeandship,项目名称:wordpress-fantastic-elasticsearch,代码行数:27,代码来源:HasChildTest.php

示例5: transform

 /**
  * Transforms an object into an elastica object having the required keys
  *
  * @param object $object the object to convert
  * @param array  $fields the keys we want to have in the returned array
  *
  * @return Document
  **/
 public function transform($object, array $fields)
 {
     $identifier = $this->propertyAccessor->getValue($object, $this->options['identifier']);
     $document = new Document($identifier);
     foreach ($fields as $key => $mapping) {
         if ($key == '_parent') {
             $property = null !== $mapping['property'] ? $mapping['property'] : $mapping['type'];
             $value = $this->propertyAccessor->getValue($object, $property);
             $document->setParent($this->propertyAccessor->getValue($value, $mapping['identifier']));
             continue;
         }
         $value = $this->propertyAccessor->getValue($object, $key);
         if (isset($mapping['type']) && in_array($mapping['type'], array('nested', 'object')) && isset($mapping['properties']) && !empty($mapping['properties'])) {
             /* $value is a nested document or object. Transform $value into
              * an array of documents, respective the mapped properties.
              */
             $document->set($key, $this->transformNested($value, $mapping['properties']));
             continue;
         }
         if (isset($mapping['type']) && $mapping['type'] == 'attachment') {
             // $value is an attachment. Add it to the document.
             if ($value instanceof \SplFileInfo) {
                 $document->addFile($key, $value->getPathName());
             } else {
                 $document->addFileContent($key, $value);
             }
             continue;
         }
         $document->set($key, $this->normalizeValue($value));
     }
     return $document;
 }
开发者ID:benstinton,项目名称:FOSElasticaBundle,代码行数:40,代码来源:ModelToElasticaAutoTransformer.php

示例6: transform

 /**
  * Transforms an object into an elastica object
  *
  * @param \Message $message the object to convert
  * @param array    $fields  the keys we want to have in the returned array
  *
  * @return Document
  **/
 public function transform($message, array $fields = array())
 {
     $data = array('content' => $message->getContent());
     $document = new Document($message->getId(), $data);
     $document->setParent($message->getGroup()->getId());
     return $document;
 }
开发者ID:kleitz,项目名称:bzion,代码行数:15,代码来源:MessageToElasticaTransformer.php

示例7: prepareSearchData

 private function prepareSearchData()
 {
     $client = $this->_getClient();
     $index = $client->getIndex('has_child_test');
     $index->create(array(), true);
     $parentType = $index->getType('parent');
     $childType = $index->getType('child');
     $childMapping = new \Elastica\Type\Mapping($childType);
     $childMapping->setParent('parent');
     $childMapping->send();
     $altType = $index->getType('alt');
     $altDoc = new Document('alt1', array('name' => 'altname'));
     $altType->addDocument($altDoc);
     $parent1 = new Document('parent1', array('id' => 'parent1', 'user' => 'parent1', 'email' => 'parent1@test.com'));
     $parentType->addDocument($parent1);
     $parent2 = new Document('parent2', array('id' => 'parent2', 'user' => 'parent2', 'email' => 'parent2@test.com'));
     $parentType->addDocument($parent2);
     $child1 = new Document('child1', array('id' => 'child1', 'user' => 'child1', 'email' => 'child1@test.com'));
     $child1->setParent('parent1');
     $childType->addDocument($child1);
     $child2 = new Document('child2', array('id' => 'child2', 'user' => 'child2', 'email' => 'child2@test.com'));
     $child2->setParent('parent2');
     $childType->addDocument($child2);
     $child3 = new Document('child3', array('id' => 'child3', 'user' => 'child3', 'email' => 'child3@test.com', 'alt' => array(array('name' => 'testname'))));
     $child3->setParent('parent2');
     $childType->addDocument($child3);
     $index->refresh();
     return $index;
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:29,代码来源:HasChildTest.php

示例8: transformObjectToDocument

 /**
  * Transforms the given object to an elastica document
  *
  * @param object $object the object to convert
  * @param array  $fields the keys we want to have in the returned array
  * @param string $identifier the identifier for the new document
  * @return Document
  */
 protected function transformObjectToDocument($object, array $fields, $identifier = '')
 {
     $document = new Document($identifier);
     foreach ($fields as $key => $mapping) {
         if ($key == '_parent') {
             $property = null !== $mapping['property'] ? $mapping['property'] : $mapping['type'];
             $value = $this->propertyAccessor->getValue($object, $property);
             $document->setParent($this->propertyAccessor->getValue($value, $mapping['identifier']));
             continue;
         }
         $path = isset($mapping['property_path']) ? $mapping['property_path'] : $key;
         if (false === $path) {
             continue;
         }
         $value = $this->propertyAccessor->getValue($object, $path);
         if (isset($mapping['type']) && in_array($mapping['type'], array('nested', 'object')) && isset($mapping['properties']) && !empty($mapping['properties'])) {
             /* $value is a nested document or object. Transform $value into
              * an array of documents, respective the mapped properties.
              */
             $document->set($key, $this->transformNested($value, $mapping['properties']));
             continue;
         }
         if (isset($mapping['type']) && $mapping['type'] == 'attachment') {
             // $value is an attachment. Add it to the document.
             if ($value instanceof \SplFileInfo) {
                 $document->addFile($key, $value->getPathName());
             } else {
                 $document->addFileContent($key, $value);
             }
             continue;
         }
         $document->set($key, $this->normalizeValue($value));
     }
     if ($this->dispatcher) {
         $event = new TransformEvent($document, $fields, $object);
         $this->dispatcher->dispatch(TransformEvent::POST_TRANSFORM, $event);
         $document = $event->getDocument();
     }
     return $document;
 }
开发者ID:anteros,项目名称:FOSElasticaBundle,代码行数:48,代码来源:ModelToElasticaAutoTransformer.php


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