本文整理汇总了PHP中Elastica\Document::setId方法的典型用法代码示例。如果您正苦于以下问题:PHP Document::setId方法的具体用法?PHP Document::setId怎么用?PHP Document::setId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Document
的用法示例。
在下文中一共展示了Document::setId方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetOptions
public function testGetOptions()
{
$document = new Document();
$document->setIndex('index');
$document->setOpType('create');
$document->setParent('2');
$document->setId(1);
$options = $document->getOptions(array('index', 'type', 'id', 'parent'));
$this->assertInternalType('array', $options);
$this->assertEquals(3, count($options));
$this->assertArrayHasKey('index', $options);
$this->assertArrayHasKey('id', $options);
$this->assertArrayHasKey('parent', $options);
$this->assertEquals('index', $options['index']);
$this->assertEquals(1, $options['id']);
$this->assertEquals('2', $options['parent']);
$this->assertArrayNotHasKey('type', $options);
$this->assertArrayNotHasKey('op_type', $options);
$this->assertArrayNotHasKey('_index', $options);
$this->assertArrayNotHasKey('_id', $options);
$this->assertArrayNotHasKey('_parent', $options);
$options = $document->getOptions(array('parent', 'op_type', 'percolate'), true);
$this->assertInternalType('array', $options);
$this->assertEquals(2, count($options));
$this->assertArrayHasKey('_parent', $options);
$this->assertArrayHasKey('_op_type', $options);
$this->assertEquals('2', $options['_parent']);
$this->assertEquals('create', $options['_op_type']);
$this->assertArrayNotHasKey('percolate', $options);
$this->assertArrayNotHasKey('op_type', $options);
$this->assertArrayNotHasKey('parent', $options);
}
示例2: update
/**
* Partial Update
*
* @param string $docId
* @param array $data
* @param integer $version
*
* @throws IndexingException
*
* @return null
*/
public function update($docId, array $data, $version = 1)
{
$document = new Document();
$document->setData($data);
$document->setId($docId);
$document->setDocAsUpsert(true);
try {
$this->getType($version)->updateDocument($document);
} catch (\Exception $e) {
throw new IndexingException('Throw exception while updating', $e->getCode(), $e);
}
}
示例3: populate
/**
* Insert the repository objects in the type index
*
* @param \Closure $loggerClosure
* @param array $options
*/
public function populate(\Closure $loggerClosure = null, array $options = array())
{
if ($loggerClosure) {
$loggerClosure('Indexing movies');
}
$allMovies = $this->movieManager->getAllMovies();
$languages = $this->getLanguagesAvailable();
foreach ($allMovies as $movie) {
$document = new Document();
$id = $movie->getId();
$document->setId($id);
$titleFr = $this->movieManager->getMovieTitleInLocale($id, $languages['fr']);
$titleEn = $this->movieManager->getMovieTitleInLocale($id, $languages['en']);
// $titleEn = $this->movieManager->getMovieTitleInLocale($id, 'en');
// $titleFr = $this->movieManager->getMovieTitleInLocale($id, 'fr');
$document->setData(array('id' => $id, 'title_fr' => $titleFr['title'], 'title_en' => $titleEn['title']));
$this->movieType->addDocuments(array($document));
}
}
示例4: 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;
}