disableSource() публичный Метод

Param can be set to true to enable again
public disableSource ( boolean $enabled = false )
$enabled boolean OPTIONAL (default = false)
Пример #1
0
 /**
  * @group functional
  */
 public function testMappingStoreFields()
 {
     $client = $this->_getClient();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $type = $index->getType('test');
     $mapping = new Mapping($type, array('firstname' => array('type' => 'string', 'store' => true), 'lastname' => array('type' => 'string')));
     $mapping->disableSource();
     $type->setMapping($mapping);
     $firstname = 'Nicolas';
     $doc = new Document(1, array('firstname' => $firstname, 'lastname' => 'Ruflin'));
     $type->addDocument($doc);
     $index->refresh();
     $queryString = new QueryString('ruflin');
     $query = Query::create($queryString);
     $query->setFields(array('*'));
     $resultSet = $type->search($query);
     $result = $resultSet->current();
     $fields = $result->getFields();
     $this->assertEquals($firstname, $fields['firstname'][0]);
     $this->assertArrayNotHasKey('lastname', $fields);
     $this->assertEquals(1, count($fields));
     $index->flush();
     $document = $type->getDocument(1);
     $this->assertEmpty($document->getData());
     $index->delete();
 }
Пример #2
0
 public function testGetIdNoSource()
 {
     // Creates a new index 'xodoa' and a type 'user' inside this index
     $indexName = 'xodoa';
     $typeName = 'user';
     $client = $this->_getClient();
     $index = $client->getIndex($indexName);
     $index->create(array(), true);
     $type = $index->getType($typeName);
     $mapping = new Mapping($type);
     $mapping->disableSource();
     $mapping->send();
     // Adds 1 document to the index
     $docId = 3;
     $doc1 = new Document($docId, array('username' => 'hans'));
     $type->addDocument($doc1);
     // Refreshes index
     $index->refresh();
     $resultSet = $type->search('hans');
     $this->assertEquals(1, $resultSet->count());
     $result = $resultSet->current();
     $this->assertEquals(array(), $result->getSource());
     $this->assertInstanceOf('Elastica\\Result', $result);
     $this->assertEquals($indexName, $result->getIndex());
     $this->assertEquals($typeName, $result->getType());
     $this->assertEquals($docId, $result->getId());
     $this->assertGreaterThan(0, $result->getScore());
     $this->assertInternalType('array', $result->getData());
 }
Пример #3
0
 /**
  * {@inheritDoc}
  */
 public function createType(ClassMetadata $metadata)
 {
     $type = $this->getIndex($metadata->index)->getType($metadata->type);
     $properties = $this->getMapping($metadata->fieldMappings);
     $rootProperties = $this->getRootMapping($metadata->rootMappings);
     $mapping = new Mapping($type, $properties);
     $mapping->disableSource($metadata->source);
     if (isset($metadata->boost)) {
         $mapping->setParam('_boost', array('name' => '_boost', 'null_value' => $metadata->boost));
     }
     if (isset($metadata->parent)) {
         $mapping->setParent($metadata->parent);
     }
     foreach ($rootProperties as $key => $value) {
         $mapping->setParam($key, $value);
     }
     $mapping->send();
     return $type;
 }
Пример #4
0
 /**
  * @group functional
  */
 public function testUpdateDocumentWithoutSource()
 {
     $index = $this->_createIndex();
     $type = $index->getType('elastica_type');
     $mapping = new Mapping();
     $mapping->setProperties(array('name' => array('type' => 'string', 'store' => 'yes'), 'counter' => array('type' => 'integer', 'store' => 'no')));
     $mapping->disableSource();
     $type->setMapping($mapping);
     $newDocument = new Document();
     $newDocument->setAutoPopulate();
     $newDocument->set('name', 'Batman');
     $newDocument->set('counter', 1);
     $type->addDocument($newDocument);
     $script = new Script('ctx._source.counter += count; ctx._source.name = name');
     $script->setId($newDocument->getId());
     $script->setParam('count', 2);
     $script->setParam('name', 'robin');
     $script->setUpsert($newDocument);
     try {
         $type->updateDocument($script);
         $this->fail('Update request should fail because source is disabled. Fields param is not set');
     } catch (ResponseException $e) {
         $error = $e->getResponse()->getError();
         $this->assertContains('document_source_missing_exception', $error['type']);
     }
     $newDocument->setFieldsSource();
     try {
         $type->updateDocument($newDocument);
         $this->fail('Update request should fail because source is disabled. Fields param is set to _source');
     } catch (ResponseException $e) {
         $error = $e->getResponse()->getError();
         $this->assertContains('document_source_missing_exception', $error['type']);
     }
 }
Пример #5
0
 protected function _createIndex($name = null, $delete = true, $shards = 1)
 {
     $index = parent::_createIndex($name, $delete, $shards);
     $type = $index->getType('.percolator');
     $mapping = new Type\Mapping($type, array('name' => array('type' => 'string'), 'field1' => array('type' => 'string')));
     $mapping->disableSource();
     $type->setMapping($mapping);
     return $index;
 }