setParent() public method

Set parent type.
public setParent ( string $type )
$type string Parent type
 /**
  * @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');
 }
 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' => '*****@*****.**'));
     $parentType->addDocument($parent1);
     $parent2 = new Document('parent2', array('id' => 'parent2', 'user' => 'parent2', 'email' => '*****@*****.**'));
     $parentType->addDocument($parent2);
     $child1 = new Document('child1', array('id' => 'child1', 'user' => 'child1', 'email' => '*****@*****.**'));
     $child1->setParent('parent1');
     $childType->addDocument($child1);
     $child2 = new Document('child2', array('id' => 'child2', 'user' => 'child2', 'email' => '*****@*****.**'));
     $child2->setParent('parent2');
     $childType->addDocument($child2);
     $child3 = new Document('child3', array('id' => 'child3', 'user' => 'child3', 'email' => '*****@*****.**', 'alt' => array(array('name' => 'testname'))));
     $child3->setParent('parent2');
     $childType->addDocument($child3);
     $index->refresh();
     return $index;
 }
Example #3
0
 /**
  * @group functional
  */
 public function testParentMapping()
 {
     $index = $this->_createIndex();
     $childtype = new Type($index, 'childtype');
     $childmapping = new Mapping($childtype, array('name' => array('type' => 'string', 'store' => true)));
     $childmapping->setParent('parenttype');
     $childtype->setMapping($childmapping);
     $data = $childmapping->toArray();
     $this->assertEquals('parenttype', $data[$childtype->getName()]['_parent']['type']);
     $parenttype = new Type($index, 'parenttype');
     $parentmapping = new Mapping($parenttype, array('name' => array('type' => 'string', 'store' => true)));
     $parenttype->setMapping($parentmapping);
 }
Example #4
0
 /**
  * {@inheritDoc}
  */
 public function createType(ClassMetadata $metadata)
 {
     $type = $this->getIndex($metadata->index)->getType($metadata->type);
     $properties = $this->getMapping($metadata->fieldMappings);
     $rootProperties = $this->getRootMapping($metadata->rootMappings);
     $mapping = new Mapping($type, $properties);
     $mapping->disableSource($metadata->source);
     if (isset($metadata->boost)) {
         $mapping->setParam('_boost', array('name' => '_boost', 'null_value' => $metadata->boost));
     }
     if (isset($metadata->parent)) {
         $mapping->setParent($metadata->parent);
     }
     foreach ($rootProperties as $key => $value) {
         $mapping->setParam($key, $value);
     }
     $mapping->send();
     return $type;
 }