本文整理汇总了PHP中Elastica\Document::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP Document::setData方法的具体用法?PHP Document::setData怎么用?PHP Document::setData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Document
的用法示例。
在下文中一共展示了Document::setData方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getDocument
/**
* Convert a log message into an Elastica Document
*
* @param array $record Log message
* @return Document
*/
protected function getDocument($record)
{
$document = new Document();
$document->setData($record);
$document->setType($this->type);
$document->setIndex($this->index);
return $document;
}
示例2: getDocument
public function getDocument($record)
{
$user = $this->token->getToken()->getUser();
$record['extra']['user'] = $user->getId();
$document = new Document();
$document->setData($record);
$document->setType($this->type);
$document->setIndex($this->index);
return $document;
}
示例3: 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);
}
}
示例4: 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));
}
}
示例5: register
/**
* {@inheritdoc}
* @see \Silex\ServiceProviderInterface::register()
*/
public function register(Application $app)
{
$app['elastic.client'] = $app->share(function () use($app) {
$config = $app['config']('elastic.connection', array());
$client = new Client($config);
return $client;
});
$app['elastic.bulk'] = $app->protect(function ($index) use($app) {
$bulk = new Bulk($app['elastic.client']);
$bulk->setIndex($index);
return $bulk;
});
$app['elastic.document'] = $app->protect(function ($type, array $data) {
$document = new Document();
$document->setType($type);
$document->setData($data);
return $document;
});
}
示例6: _populateDocumentFieldsFromResponse
/**
* @param \Elastica\Response $response
* @param \Elastica\Document $document
* @param string $fields Array of field names to be populated or '_source' if whole document data should be updated
*/
protected function _populateDocumentFieldsFromResponse(Response $response, Document $document, $fields)
{
$responseData = $response->getData();
if ('_source' == $fields) {
if (isset($responseData['get']['_source']) && is_array($responseData['get']['_source'])) {
$document->setData($responseData['get']['_source']);
}
} else {
$keys = explode(',', $fields);
$data = $document->getData();
foreach ($keys as $key) {
if (isset($responseData['get']['fields'][$key])) {
$data[$key] = $responseData['get']['fields'][$key];
} elseif (isset($data[$key])) {
unset($data[$key]);
}
}
$document->setData($data);
}
}
示例7: logStringQuery
/**
* {@inheritdoc}
*/
public function logStringQuery($searchTerm, $ipAddress)
{
$document = new Document();
$document->setData(array('search_term' => $searchTerm, 'ip_address' => $ipAddress));
$this->type->addDocuments(array($document));
}
示例8: addObjects
/**
* Uses _bulk to send documents to the server
*
* @param objects[] $objects
* @return \Elastica\Bulk\ResponseSet
* @link http://www.elasticsearch.org/guide/reference/api/bulk.html
*/
public function addObjects(array $objects)
{
if (!isset($this->_serializer)) {
throw new RuntimeException('No serializer defined');
}
$docs = array();
foreach ($objects as $object) {
$data = call_user_func($this->_serializer, $object);
$doc = new Document();
$doc->setData($data);
$doc->setType($this->getName());
$docs[] = $doc;
}
return $this->getIndex()->addDocuments($docs);
}
示例9: testUpsert
/**
* @group unit
*/
public function testUpsert()
{
$document = new Document();
$upsert = new Document();
$upsert->setData(array('someproperty' => 'somevalue'));
$this->assertFalse($document->hasUpsert());
$document->setUpsert($upsert);
$this->assertTrue($document->hasUpsert());
$this->assertSame($upsert, $document->getUpsert());
}
示例10: testSetData
public function testSetData()
{
$doc = new Document();
$returnValue = $doc->setData(array('data'));
$this->assertInstanceOf('Elastica\\Document', $returnValue);
}
示例11: addObject
public function addObject($object, Document $doc = null)
{
if (!isset($this->_serializer)) {
throw new RuntimeException('No serializer defined');
}
$data = call_user_func($this->_serializer, $object);
if (!$doc) {
$doc = new Document();
}
$doc->setData($data);
return $this->addDocument($doc);
}