本文整理汇总了PHP中Elastica\Document::hasVersion方法的典型用法代码示例。如果您正苦于以下问题:PHP Document::hasVersion方法的具体用法?PHP Document::hasVersion怎么用?PHP Document::hasVersion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Document
的用法示例。
在下文中一共展示了Document::hasVersion方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testUpdateDocumentWithFieldsSource
/**
* @group functional
*/
public function testUpdateDocumentWithFieldsSource()
{
$this->_checkScriptInlineSetting();
$client = $this->_getClient();
$index = $client->getIndex('elastica_test');
$type = $index->getType('update_type');
$client->setConfigValue('document', array('autoPopulate' => true));
$newDocument = new Document(null, array('counter' => 5, 'name' => 'Batman'));
$this->assertFalse($newDocument->hasVersion());
$response = $type->addDocument($newDocument);
$responseData = $response->getData();
$this->assertTrue($newDocument->hasVersion());
$this->assertArrayHasKey('_version', $responseData, '_version is missing in response data it is weird');
$this->assertEquals(1, $responseData['_version']);
$this->assertEquals($responseData['_version'], $newDocument->getVersion());
$this->assertTrue($newDocument->hasId());
$script = new Script('ctx._source.counter += count; ctx._source.realName = realName');
$script->setId($newDocument->getId());
$script->setParam('count', 7);
$script->setParam('realName', 'Bruce Wayne');
$script->setUpsert($newDocument);
$newDocument->setFieldsSource();
$response = $type->updateDocument($script);
$responseData = $response->getData();
$data = $type->getDocument($newDocument->getId())->getData();
$this->assertEquals(12, $data['counter']);
$this->assertEquals('Batman', $data['name']);
$this->assertEquals('Bruce Wayne', $data['realName']);
$this->assertTrue($newDocument->hasVersion());
$this->assertArrayHasKey('_version', $responseData, '_version is missing in response data it is weird');
$this->assertEquals(2, $responseData['_version']);
$document = $type->getDocument($newDocument->getId());
}