示例#1
0
 public function testParent()
 {
     $index = $this->_createIndex();
     $typeBlog = new Elastica_Type($index, 'blog');
     $typeComment = new Elastica_Type($index, 'comment');
     $mapping = new Elastica_Type_Mapping();
     $mapping->setParam('_parent', array('type' => 'blog'));
     $typeComment->setMapping($mapping);
     $entry1 = new Elastica_Document(1);
     $entry1->add('title', 'Hello world');
     $typeBlog->addDocument($entry1);
     $entry2 = new Elastica_Document(2);
     $entry2->add('title', 'Foo bar');
     $typeBlog->addDocument($entry2);
     $entry3 = new Elastica_Document(3);
     $entry3->add('title', 'Till dawn');
     $typeBlog->addDocument($entry3);
     $comment = new Elastica_Document(1);
     $comment->add('author', 'Max');
     $comment->setParent(2);
     // Entry Foo bar
     $typeComment->addDocument($comment);
     $index->optimize();
     $query = new Elastica_Query_HasChild('Max', 'comment');
     $resultSet = $typeBlog->search($query);
     $this->assertEquals(1, $resultSet->count());
     $this->assertEquals(array('title' => 'Foo bar'), $resultSet->current()->getData());
 }
示例#2
0
 public function testParentMapping()
 {
     $index = $this->_createIndex();
     $parenttype = new Elastica_Type($index, 'parenttype');
     $parentmapping = new Elastica_Type_Mapping($parenttype, array('name' => array('type' => 'string', 'store' => 'yes')));
     $parenttype->setMapping($parentmapping);
     $childtype = new Elastica_Type($index, 'childtype');
     $childmapping = new Elastica_Type_Mapping($childtype, array('name' => array('type' => 'string', 'store' => 'yes')));
     $childmapping->setParam('_parent', array('type' => 'parenttype'));
     $childtype->setMapping($childmapping);
 }
 public static function createType($handle)
 {
     self::init();
     $local_type = self::getTypeByHandle($handle);
     $mapping = json_decode($local_type->mapping_json, TRUE);
     $type = new Elastica_Type(self::getIndex(), $handle);
     $type_mapping = new Elastica_Type_Mapping($type);
     foreach ($mapping[$handle] as $key => $value) {
         $type_mapping->setParam($key, $value);
     }
     $type->setMapping($type_mapping);
     self::getIndex()->refresh();
 }