本文整理汇总了PHP中Elastica\Type\Mapping::disableSource方法的典型用法代码示例。如果您正苦于以下问题:PHP Mapping::disableSource方法的具体用法?PHP Mapping::disableSource怎么用?PHP Mapping::disableSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Type\Mapping
的用法示例。
在下文中一共展示了Mapping::disableSource方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMappingStoreFields
/**
* @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: testGetIdNoSource
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: createType
/**
* {@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: testUpdateDocumentWithoutSource
/**
* @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: _createIndex
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;
}