本文整理汇总了PHP中Elastica\Type\Mapping::setParent方法的典型用法代码示例。如果您正苦于以下问题:PHP Mapping::setParent方法的具体用法?PHP Mapping::setParent怎么用?PHP Mapping::setParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Type\Mapping
的用法示例。
在下文中一共展示了Mapping::setParent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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');
}
示例2: _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;
}
示例3: testParentMapping
/**
* @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);
}
示例4: createType
/**
* {@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;
}