本文整理汇总了PHP中Elastica\Document类的典型用法代码示例。如果您正苦于以下问题:PHP Document类的具体用法?PHP Document怎么用?PHP Document使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Document类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: transform
/**
* Transforms an object into an elastica object
*
* @param \Message $message the object to convert
* @param array $fields the keys we want to have in the returned array
*
* @return Document
**/
public function transform($message, array $fields = array())
{
$data = array('content' => $message->getContent());
$document = new Document($message->getId(), $data);
$document->setParent($message->getGroup()->getId());
return $document;
}
开发者ID:kleitz,项目名称:bzion,代码行数:15,代码来源:MessageToElasticaTransformer.php
示例2: testHasParent
/**
* @group functional
*/
public function testHasParent()
{
$index = $this->_createIndex();
$shopType = $index->getType('shop');
$productType = $index->getType('product');
$mapping = new Mapping();
$mapping->setParent('shop');
$productType->setMapping($mapping);
$shopType->addDocuments(array(new Document('zurich', array('brand' => 'google')), new Document('london', array('brand' => 'apple'))));
$doc1 = new Document(1, array('device' => 'chromebook'));
$doc1->setParent('zurich');
$doc2 = new Document(2, array('device' => 'macmini'));
$doc2->setParent('london');
$productType->addDocument($doc1);
$productType->addDocument($doc2);
$index->refresh();
// All documents
$parentQuery = new HasParent(new MatchAll(), $shopType->getName());
$search = new Search($index->getClient());
$results = $search->search($parentQuery);
$this->assertEquals(2, $results->count());
$match = new Match();
$match->setField('brand', 'google');
$parentQuery = new HasParent($match, $shopType->getName());
$search = new Search($index->getClient());
$results = $search->search($parentQuery);
$this->assertEquals(1, $results->count());
$result = $results->current();
$data = $result->getData();
$this->assertEquals($data['device'], 'chromebook');
}
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:34,代码来源:HasParentTest.php
示例3: testGeoPoint
public function testGeoPoint()
{
$client = $this->_getClient();
$index = $client->getIndex('test');
$index->create(array(), true);
$type = $index->getType('test');
// Set mapping
$type->setMapping(array('point' => array('type' => 'geo_point')));
// Add doc 1
$doc1 = new Document(1, array('name' => 'ruflin'));
$doc1->addGeoPoint('point', 17, 19);
$type->addDocument($doc1);
// Add doc 2
$doc2 = new Document(2, array('name' => 'ruflin'));
$doc2->addGeoPoint('point', 30, 40);
$type->addDocument($doc2);
$index->optimize();
$index->refresh();
// Only one point should be in radius
$query = new Query();
$geoFilter = new GeoDistance('point', array('lat' => 30, 'lon' => 40), '1km');
$query = new Query(new MatchAll());
$query->setFilter($geoFilter);
$this->assertEquals(1, $type->search($query)->count());
// Both points should be inside
$query = new Query();
$geoFilter = new GeoDistance('point', array('lat' => 30, 'lon' => 40), '40000km');
$query = new Query(new MatchAll());
$query->setFilter($geoFilter);
$index->refresh();
$this->assertEquals(2, $type->search($query)->count());
}
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:32,代码来源:GeoDistanceTest.php
示例4: prepareSearchData
private function prepareSearchData()
{
$client = $this->_getClient();
$index = $client->getIndex('has_child_test');
$index->create(array(), true);
$parentType = $index->getType('parent');
$childType = $index->getType('child');
$childMapping = new \Elastica\Type\Mapping($childType);
$childMapping->setParent('parent');
$childMapping->send();
$altType = $index->getType('alt');
$altDoc = new Document('alt1', array('name' => 'altname'));
$altType->addDocument($altDoc);
$parent1 = new Document('parent1', array('id' => 'parent1', 'user' => 'parent1', 'email' => '[email protected]'));
$parentType->addDocument($parent1);
$parent2 = new Document('parent2', array('id' => 'parent2', 'user' => 'parent2', 'email' => '[email protected]'));
$parentType->addDocument($parent2);
$child1 = new Document('child1', array('id' => 'child1', 'user' => 'child1', 'email' => '[email protected]'));
$child1->setParent('parent1');
$childType->addDocument($child1);
$child2 = new Document('child2', array('id' => 'child2', 'user' => 'child2', 'email' => '[email protected]'));
$child2->setParent('parent2');
$childType->addDocument($child2);
$child3 = new Document('child3', array('id' => 'child3', 'user' => 'child3', 'email' => '[email protected]', 'alt' => array(array('name' => 'testname'))));
$child3->setParent('parent2');
$childType->addDocument($child3);
$index->refresh();
return $index;
}
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:29,代码来源:HasChildTest.php
示例5: testGeoPoint
/**
* @group functional
*/
public function testGeoPoint()
{
$index = $this->_createIndex();
$type = $index->getType('test');
// Set mapping
$type->setMapping(array('location' => array('type' => 'geo_point')));
// Add doc 1
$doc1 = new Document(1, array('name' => 'ruflin'));
$doc1->addGeoPoint('location', 17, 19);
$type->addDocument($doc1);
// Add doc 2
$doc2 = new Document(2, array('name' => 'ruflin'));
$doc2->addGeoPoint('location', 30, 40);
$type->addDocument($doc2);
$index->refresh();
// Only one point should be in polygon
$query = new Query();
$points = array(array(16, 16), array(16, 20), array(20, 20), array(20, 16), array(16, 16));
$geoFilter = new GeoPolygon('location', $points);
$query = new Query(new MatchAll());
$query->setPostFilter($geoFilter);
$this->assertEquals(1, $type->search($query)->count());
// Both points should be inside
$query = new Query();
$points = array(array(16, 16), array(16, 40), array(40, 40), array(40, 16), array(16, 16));
$geoFilter = new GeoPolygon('location', $points);
$query = new Query(new MatchAll());
$query->setPostFilter($geoFilter);
$this->assertEquals(2, $type->search($query)->count());
}
开发者ID:vinusebastian,项目名称:Elastica,代码行数:33,代码来源:GeoPolygonTest.php
示例6: unmarshal
/**
* @param Document|array $documentOrSource Document object or source array
* @return Message
*
* @throws \Exception
* @throws GdbotsPbjException
*/
public function unmarshal($documentOrSource)
{
if ($documentOrSource instanceof Document) {
return $this->doUnmarshal($documentOrSource->getData());
}
return $this->doUnmarshal($documentOrSource);
}
开发者ID:gdbots,项目名称:pbj-php,代码行数:14,代码来源:DocumentMarshaler.php
示例7: updateElasticsearchDocument
/**
* Populate elastica with the location of the photograph
* @param \Elastica\Document $document Representation of an Elastic Search document
* @return \Elastica\Document modified version of the document
*/
public function updateElasticsearchDocument(\Elastica\Document $document)
{
// self::$ctr++;
$coors = array('lat' => $this->owner->Lat, 'lon' => $this->owner->Lon);
$document->set('location', $coors);
$sortable = $this->owner->ShutterSpeed;
$sortable = explode('/', $sortable);
if (sizeof($sortable) == 1) {
$sortable = trim($sortable[0]);
if ($this->owner->ShutterSpeed == null) {
$sortable = null;
}
if ($sortable === '1') {
$sortable = '1.000000';
}
} else {
if (sizeof($sortable) == 2) {
$sortable = floatval($sortable[0]) / intval($sortable[1]);
$sortable = round($sortable, 6);
}
}
$sortable = $sortable . '|' . $this->owner->ShutterSpeed;
$document->set('ShutterSpeed', $sortable);
return $document;
}
开发者ID:gordonbanderson,项目名称:flickr-editor,代码行数:30,代码来源:FlickrPhotoElasticaIndexingExtension.php
示例8: _getTestIndex
protected function _getTestIndex()
{
$index = $this->_createIndex('has_child_test');
$parentType = $index->getType('parent');
$childType = $index->getType('child');
$childMapping = new Mapping($childType);
$childMapping->setParent('parent');
$childMapping->send();
$altType = $index->getType('alt');
$altDoc = new Document('alt1', array('name' => 'altname'));
$altType->addDocument($altDoc);
$parent1 = new Document('parent1', array('id' => 'parent1', 'user' => 'parent1', 'email' => '[email protected]'));
$parentType->addDocument($parent1);
$parent2 = new Document('parent2', array('id' => 'parent2', 'user' => 'parent2', 'email' => '[email protected]'));
$parentType->addDocument($parent2);
$child1 = new Document('child1', array('id' => 'child1', 'user' => 'child1', 'email' => '[email protected]'));
$child1->setParent('parent1');
$childType->addDocument($child1);
$child2 = new Document('child2', array('id' => 'child2', 'user' => 'child2', 'email' => '[email protected]'));
$child2->setParent('parent2');
$childType->addDocument($child2);
$child3 = new Document('child3', array('id' => 'child3', 'user' => 'child3', 'email' => '[email protected]', 'alt' => array(array('name' => 'testname'))));
$child3->setParent('parent2');
$childType->addDocument($child3);
$index->refresh();
return $index;
}
开发者ID:makeandship,项目名称:wordpress-fantastic-elasticsearch,代码行数:27,代码来源:HasChildTest.php
示例9: toDocument
/**
* {@inheritDoc}
*/
public function toDocument(Model $model, Document $document)
{
$mapping = ['city' => 'city', 'state' => 'state', 'country' => 'country', 'zip_code' => 'zip_code'];
foreach ($mapping as $field => $key) {
$document->set($key, $model->{$field});
}
if (!empty($model->lat) && !empty($model->lon)) {
$document->set('location', ['lon' => $model->lon, 'lat' => $model->lat]);
}
$fullAddress = [];
if (!empty($model->city)) {
$fullAddress[] = $model->city;
}
if (!empty($model->state)) {
$fullAddress[] = $model->state;
}
if (!empty($model->zip_code)) {
$fullAddress[] = $model->zip_code;
}
if (!empty($model->country)) {
$fullAddress[] = $model->country;
}
$document->set('full_address', implode(', ', $fullAddress));
return $document;
}
开发者ID:phpfour,项目名称:ah,代码行数:28,代码来源:LocationTransformer.php
示例10: 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;
}
开发者ID:saj696,项目名称:pipe,代码行数:14,代码来源:ElasticaFormatter.php
示例11: 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;
}
开发者ID:ABeloeil,项目名称:lift,代码行数:10,代码来源:ElasticaFormatter.php
示例12: __construct
/**
* DocumentFactory constructor.
*
* @param Document $prototype
*/
public function __construct(Document $prototype)
{
if ($prototype->getIndex() === '' || $prototype->getType() === '') {
throw new \InvalidArgumentException('prototype not properly inited');
}
$this->docPrototype = $prototype;
$fieldValuePairs = get_object_vars(new User());
array_walk($fieldValuePairs, function ($value, $field) {
$this->fieldList[$field] = gettype($value);
});
}
开发者ID:jiangyu7408,项目名称:notification,代码行数:16,代码来源:DocumentFactory.php
示例13: __construct
/**
* ElasticaHelper constructor.
*
* @param string $gameVersion
* @param string $indexName
* @param int $magicNumber
*/
public function __construct($gameVersion, $indexName, $magicNumber = 500)
{
$docPrototype = new Document();
$docPrototype->setIndex($indexName)->setType('user:' . $gameVersion);
$this->documentFactory = new DocumentFactory($docPrototype);
$this->elastica = $this->makeElastica();
$this->magicNumber = $magicNumber;
$this->errorHandler = function (\Exception $exception) {
error_log(print_r($exception->getMessage(), true), 3, CONFIG_DIR . '/elastica.error');
};
}
开发者ID:jiangyu7408,项目名称:notification,代码行数:18,代码来源:ElasticaHelper.php
示例14: indexExtraFields
/**
* @param Document $document
* @param Content $content
*/
public function indexExtraFields(Document $document, Content $content)
{
if (!$content instanceof EntityContent || $content->isRedirect() === true) {
return;
}
$fields = $this->fieldDefinitions->getFields();
$entity = $content->getEntity();
foreach ($fields as $fieldName => $field) {
$data = $field->getFieldData($entity);
$document->set($fieldName, $data);
}
}
开发者ID:Benestar,项目名称:mediawiki-extensions-Wikibase,代码行数:16,代码来源:CirrusSearchHookHandlers.php
示例15: 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);
}
}
开发者ID:biberlabs,项目名称:zf2-boilerplate,代码行数:23,代码来源:AbstractIndexService.php
示例16: transform
/**
* Transforms an object into an elastica object having the required keys
*
* @param object $object the object to convert
* @param array $fields the keys we want to have in the returned array
*
* @return Document
**/
public function transform($object, array $fields)
{
$identifier = $this->propertyAccessor->getValue($object, $this->options['identifier']);
$document = new Document($identifier);
foreach ($fields as $key => $mapping) {
if ($key == '_parent') {
$property = null !== $mapping['property'] ? $mapping['property'] : $mapping['type'];
$value = $this->propertyAccessor->getValue($object, $property);
$document->setParent($this->propertyAccessor->getValue($value, $mapping['identifier']));
continue;
}
$value = $this->propertyAccessor->getValue($object, $key);
if (isset($mapping['type']) && in_array($mapping['type'], array('nested', 'object')) && isset($mapping['properties']) && !empty($mapping['properties'])) {
/* $value is a nested document or object. Transform $value into
* an array of documents, respective the mapped properties.
*/
$document->set($key, $this->transformNested($value, $mapping['properties']));
continue;
}
if (isset($mapping['type']) && $mapping['type'] == 'attachment') {
// $value is an attachment. Add it to the document.
if ($value instanceof \SplFileInfo) {
$document->addFile($key, $value->getPathName());
} else {
$document->addFileContent($key, $value);
}
continue;
}
$document->set($key, $this->normalizeValue($value));
}
return $document;
}
开发者ID:benstinton,项目名称:FOSElasticaBundle,代码行数:40,代码来源:ModelToElasticaAutoTransformer.php
示例17: 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;
});
}
开发者ID:skymeyer,项目名称:csp-report-collector,代码行数:23,代码来源:ElasticService.php
示例18: 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));
}
}
开发者ID:ChristWood,项目名称:videoCollection,代码行数:25,代码来源:TitleProvider.php
示例19: testSearchRequest
/**
* @dataProvider configProvider
*/
public function testSearchRequest($config)
{
// Creates a new index 'xodoa' and a type 'user' inside this index
$client = new Client($config);
$index = $client->getIndex('elastica_test1');
$index->create(array(), true);
$type = $index->getType('user');
// Adds 1 document to the index
$doc1 = new Document(1, array('username' => 'hans', 'test' => array('2', '3', '5')));
$doc1->setVersion(0);
$type->addDocument($doc1);
// Adds a list of documents with _bulk upload to the index
$docs = array();
$docs[] = new Document(2, array('username' => 'john', 'test' => array('1', '3', '6')));
$docs[] = new Document(3, array('username' => 'rolf', 'test' => array('2', '3', '7')));
$type->addDocuments($docs);
// Refresh index
$index->refresh();
$resultSet = $type->search('rolf');
$this->assertEquals(1, $resultSet->getTotalHits());
}
开发者ID:kskod,项目名称:Elastica,代码行数:24,代码来源:ThriftTest.php
示例20: toDocument
/**
* {@inheritDoc}
*/
public function toDocument(Model $model, Document $document)
{
foreach ($this->mapping as $field => $key) {
$document->set($key, $model->{$field});
}
if (!empty($model->job_ziplat) && !empty($model->job_ziplon)) {
$document->set('location', $model->job_ziplat . ',' . $model->job_ziplon);
}
$fullAddress = [];
if (!empty($model->job_address)) {
$fullAddress[] = $model->job_address;
}
if (!empty($model->city)) {
$fullAddress[] = $model->city;
}
if (!empty($model->job_postcode)) {
$fullAddress[] = $model->job_postcode;
}
$document->set('full_address', implode(', ', $fullAddress));
return $document;
}
开发者ID:phpfour,项目名称:ah,代码行数:24,代码来源:JobTransformer.php
注:本文中的Elastica\Document类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论