本文整理汇总了PHP中Elastica\Document::hasId方法的典型用法代码示例。如果您正苦于以下问题:PHP Document::hasId方法的具体用法?PHP Document::hasId怎么用?PHP Document::hasId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Document
的用法示例。
在下文中一共展示了Document::hasId方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testHasId
public function testHasId()
{
$document = new Document();
$this->assertFalse($document->hasId());
$document->setId('');
$this->assertFalse($document->hasId());
$document->setId(0);
$this->assertTrue($document->hasId());
$document->setId('hello');
$this->assertTrue($document->hasId());
}
示例2: addDocument
/**
* Adds the given document to the search index
*
* @param \Elastica\Document $doc Document with data
* @return \Elastica\Response
*/
public function addDocument(Document $doc)
{
$path = urlencode($doc->getId());
$type = Request::PUT;
// If id is empty, POST has to be used to automatically create id
if (empty($path)) {
$type = Request::POST;
}
$options = $doc->getOptions(array('version', 'version_type', 'routing', 'percolate', 'parent', 'ttl', 'timestamp', 'op_type', 'consistency', 'replication', 'refresh', 'timeout'));
$response = $this->request($path, $type, $doc->getData(), $options);
$data = $response->getData();
// set autogenerated id to document
if (($doc->isAutoPopulate() || $this->getIndex()->getClient()->getConfigValue(array('document', 'autoPopulate'), false)) && $response->isOk()) {
if (!$doc->hasId()) {
if (isset($data['_id'])) {
$doc->setId($data['_id']);
}
}
if (isset($data['_version'])) {
$doc->setVersion($data['_version']);
}
}
return $response;
}
示例3: updateDocument
/**
* Update document, using update script. Requires elasticsearch >= 0.19.0
*
* @param \Elastica\Document $document Document with update data
* @throws \Elastica\Exception\InvalidException
* @return \Elastica\Response
* @link http://www.elasticsearch.org/guide/reference/api/update.html
*/
public function updateDocument(Document $document)
{
if (!$document->hasId()) {
throw new InvalidException('Document id is not set');
}
return $this->getIndex()->getClient()->updateDocument($document->getId(), $document, $this->getIndex()->getName(), $this->getName());
}
示例4: updateDocument
/**
* Update document, using update script. Requires elasticsearch >= 0.19.0
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html
* @throws \Elastica\Exception\InvalidException
*
* @param \Elastica\Document|\Elastica\Script $data Document with update data
* @param array $options array of query params to use for query. For possible options check es api
* @return \Elastica\Response
*/
public function updateDocument($data, array $options = array())
{
if (!$data instanceof Document && !$data instanceof Script) {
throw new \InvalidArgumentException("Data should be a Document or Script");
}
if (!$data->hasId()) {
throw new InvalidException('Document or Script id is not set');
}
$id = urlencode($data->getId());
return $this->getIndex()->getClient()->updateDocument($id, $data, $this->getIndex()->getName(), $this->getName(), $options);
}
示例5: testAddDocumentAutoGeneratedId
/**
* @group functional
*/
public function testAddDocumentAutoGeneratedId()
{
$index = $this->_createIndex();
$type = $index->getType('elastica_type');
$document = new Document();
$document->setAutoPopulate();
$document->set('name', 'ruflin');
$this->assertEquals('', $document->getId());
$this->assertFalse($document->hasId());
$type->addDocument($document);
$this->assertNotEquals('', $document->getId());
$this->assertTrue($document->hasId());
$foundDoc = $type->getDocument($document->getId());
$this->assertInstanceOf('Elastica\\Document', $foundDoc);
$this->assertEquals($document->getId(), $foundDoc->getId());
$data = $foundDoc->getData();
$this->assertArrayHasKey('name', $data);
$this->assertEquals('ruflin', $data['name']);
}