本文整理匯總了PHP中Elastica\Document::getId方法的典型用法代碼示例。如果您正苦於以下問題:PHP Document::getId方法的具體用法?PHP Document::getId怎麽用?PHP Document::getId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Elastica\Document
的用法示例。
在下文中一共展示了Document::getId方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: moreLikeThis
/**
* More like this query based on the given object
*
* The id in the given object has to be set
*
* @param \Elastica\Document $doc Document to query for similar objects
* @param array $params OPTIONAL Additional arguments for the query
* @param string|array|\Elastica\Query $query OPTIONAL Query to filter the moreLikeThis results
* @return \Elastica\ResultSet ResultSet with all results inside
* @link http://www.elasticsearch.org/guide/reference/api/more-like-this.html
*/
public function moreLikeThis(Document $doc, $params = array(), $query = array())
{
$path = $doc->getId() . '/_mlt';
$query = Query::create($query);
$response = $this->request($path, Request::GET, $query->toArray(), $params);
return new ResultSet($response, $query);
}
示例2: deleteDocument
/**
* @param \Elastica\Document $document
*
* @return \Elastica\Response
*/
public function deleteDocument(Document $document)
{
$options = $document->getOptions(array('version', 'version_type', 'routing', 'parent', 'replication', 'consistency', 'refresh', 'timeout'));
return $this->deleteById($document->getId(), $options);
}
示例3: 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);
}
示例4: 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']);
}