当前位置: 首页>>代码示例>>PHP>>正文


PHP Document::set方法代码示例

本文整理汇总了PHP中Elastica\Document::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Document::set方法的具体用法?PHP Document::set怎么用?PHP Document::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Elastica\Document的用法示例。


在下文中一共展示了Document::set方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: testMatchDoc

 public function testMatchDoc()
 {
     $client = new Client(array('persistent' => false));
     $index = $client->getIndex('elastica_test');
     $index->create(array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0)), true);
     $percolator = new Percolator($index);
     $percolatorName = 'percotest';
     $query = new Term(array('name' => 'ruflin'));
     $response = $percolator->registerQuery($percolatorName, $query);
     $this->assertTrue($response->isOk());
     $this->assertFalse($response->hasError());
     $doc1 = new Document();
     $doc1->set('name', 'ruflin');
     $doc2 = new Document();
     $doc2->set('name', 'nicolas');
     $index = new Index($index->getClient(), '_percolator');
     $index->optimize();
     $index->refresh();
     $matches1 = $percolator->matchDoc($doc1);
     $this->assertTrue(in_array($percolatorName, $matches1));
     $this->assertEquals(1, count($matches1));
     $matches2 = $percolator->matchDoc($doc2);
     $this->assertEmpty($matches2);
 }
开发者ID:kskod,项目名称:Elastica,代码行数:24,代码来源:PercolatorTest.php

示例7: testAddDocumentVersion

 public function testAddDocumentVersion()
 {
     $client = $this->_getClient();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $type = new Type($index, 'test');
     $doc1 = new Document(1);
     $doc1->set('title', 'Hello world');
     $return = $type->addDocument($doc1);
     $data = $return->getData();
     $this->assertEquals(1, $data['_version']);
     $return = $type->addDocument($doc1);
     $data = $return->getData();
     $this->assertEquals(2, $data['_version']);
 }
开发者ID:kskod,项目名称:Elastica,代码行数:15,代码来源:IndexTest.php

示例8: testSerializedData

 /**
  * @group unit
  */
 public function testSerializedData()
 {
     $data = '{"user":"rolf"}';
     $document = new Document(1, $data);
     $this->assertFalse($document->has('user'));
     try {
         $document->get('user');
         $this->fail('User field should not be available');
     } catch (InvalidException $e) {
         $this->assertTrue(true);
     }
     try {
         $document->remove('user');
         $this->fail('User field should not be available for removal');
     } catch (InvalidException $e) {
         $this->assertTrue(true);
     }
     try {
         $document->set('name', 'shawn');
         $this->fail('Document should not allow to set new data');
     } catch (InvalidException $e) {
         $this->assertTrue(true);
     }
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:27,代码来源:DocumentTest.php

示例9: testRegisterAndUnregisterPercolator

 /**
  * Test case for using filtered percolator queries based on the Elasticsearch documentation examples.
  */
 public function testRegisterAndUnregisterPercolator()
 {
     // step one: register create index and setup the percolator query from the ES documentation.
     $index = $this->_createIndex();
     $percolator = new Percolator($index);
     $baseQuery = new Term(array('field1' => 'value1'));
     $fields = array('color' => 'blue');
     $response = $percolator->registerQuery('kuku', $baseQuery, $fields);
     $this->assertTrue($response->isOk());
     $this->assertFalse($response->hasError());
     // refreshing is required in order to ensure the query is really ready for execution.
     $index->refresh();
     // step two: match a document which should match the kuku query when filtered on the blue color
     $doc = new Document();
     $doc->set('field1', 'value1');
     $matches = $percolator->matchDoc($doc, new Term(array('color' => 'blue')));
     $this->assertCount(1, $matches, 'No or too much registered query matched.');
     $this->assertEquals('kuku', $matches[0]['_id'], 'A wrong registered query has matched.');
     // step three: validate that using a different color, no registered query matches.
     $matches = $percolator->matchDoc($doc, new Term(array('color' => 'green')));
     $this->assertCount(0, $matches, 'A registered query matched, although nothing should match at all.');
     // unregister percolator query
     $response = $percolator->unregisterQuery('kuku');
     $this->assertTrue($response->isOk());
     $this->assertFalse($response->hasError());
     // refreshing is required in order to ensure the query is really ready for execution.
     $index->refresh();
     $matches = $percolator->matchDoc($doc, new Term(array('color' => 'blue')));
     $this->assertCount(0, $matches, 'Percolator query did not get deleted.');
     $index->delete();
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:34,代码来源:PercolatorTest.php

示例10: 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']);
 }
开发者ID:bungkoko,项目名称:Elastica,代码行数:22,代码来源:TypeTest.php

示例11: transformObjectToDocument

 /**
  * Transforms the given object to an elastica document
  *
  * @param object $object the object to convert
  * @param array  $fields the keys we want to have in the returned array
  * @param string $identifier the identifier for the new document
  * @return Document
  */
 protected function transformObjectToDocument($object, array $fields, $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;
         }
         $path = isset($mapping['property_path']) ? $mapping['property_path'] : $key;
         if (false === $path) {
             continue;
         }
         $value = $this->propertyAccessor->getValue($object, $path);
         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));
     }
     if ($this->dispatcher) {
         $event = new TransformEvent($document, $fields, $object);
         $this->dispatcher->dispatch(TransformEvent::POST_TRANSFORM, $event);
         $document = $event->getDocument();
     }
     return $document;
 }
开发者ID:anteros,项目名称:FOSElasticaBundle,代码行数:48,代码来源:ModelToElasticaAutoTransformer.php

示例12: testPercolateWithAdditionalRequestBodyOptions

 /**
  * @group functional
  */
 public function testPercolateWithAdditionalRequestBodyOptions()
 {
     $index = $this->_createIndex();
     $percolator = new Percolator($index);
     $query = new Term(array('name' => 'foo'));
     $response = $percolator->registerQuery('percotest', $query, array('field1' => array('tag1', 'tag2')));
     $this->assertTrue($response->isOk());
     $this->assertFalse($response->hasError());
     $query = new Term(array('name' => 'foo'));
     $response = $percolator->registerQuery('percotest1', $query, array('field1' => array('tag2')));
     $this->assertTrue($response->isOk());
     $this->assertFalse($response->hasError());
     $doc1 = new Document();
     $doc1->set('name', 'foo');
     $index->refresh();
     $options = array('track_scores' => true, 'sort' => array('_score' => 'desc'), 'size' => 1);
     $matches = $percolator->matchDoc($doc1, new Term(array('field1' => 'tag2')), 'type', $options);
     $this->assertCount(1, $matches);
     $this->assertEquals('percotest1', $matches[0]['_id']);
     $this->assertArrayHasKey('_score', $matches[0]);
 }
开发者ID:bungkoko,项目名称:Elastica,代码行数:24,代码来源:PercolatorTest.php

示例13: pushDocument

 /**
  * add a document to the list. To index all the list execute flushDocuments
  * 
  * @param   \Elastica\Document   $document
  * */
 protected function pushDocument($document)
 {
     // Get language if exists
     $lang = $document->__isset('language') ? $document->language : '*';
     //Add boost field if does not exist
     if (!$document->__isset('boost') && $this->boost) {
         $document->set('boost', $this->boost);
     }
     // Extract the first letter of the langue (en for en-GB)
     $explode = explode('-', $lang);
     $lang = $explode[0];
     // If it is the first of this language
     if (!array_key_exists($lang, $this->documents)) {
         $this->documents[$lang] = array();
         // Init array
     }
     // add document to the list
     $this->documents[$lang][] = $document;
     $mem_limit_bytes = trim(ini_get('memory_limit')) * 1024 * 1024;
     if (memory_get_usage() > $mem_limit_bytes * 0.2) {
         // Check memory use
         //if documents array is too big we flush it
         $this->flushDocuments();
     }
 }
开发者ID:joomlacorner,项目名称:jes,代码行数:30,代码来源:adapter.php

示例14: setValue

 /**
  * @param $config
  * @param $fieldName
  * @param \Elastica\Document $document
  * @param $fieldValue
  */
 public function setValue($config, $fieldName, $document, $fieldValue)
 {
     switch ($config['type']) {
         case 'date':
             if ($fieldValue) {
                 $document->set($fieldName, $this->formatDate($fieldValue));
             }
             break;
         default:
             $document->set($fieldName, $fieldValue);
             break;
     }
 }
开发者ID:heyday,项目名称:silverstripe-elastica,代码行数:19,代码来源:Searchable.php


注:本文中的Elastica\Document::set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。