Doctrine\Search\Mapping\ClassMetadata::mapField PHP Method

mapField() public method

Adds a mapped field to the class.
public mapField ( array $mapping ) : void
$mapping array The field mapping.
return void
    public function mapField(array $mapping)
    {
        if (isset($this->fieldMappings[$mapping['fieldName']])) {
            throw MappingException::duplicateFieldMapping($this->className, $mapping['fieldName']);
        }
        $this->fieldMappings[$mapping['fieldName']] = $mapping;
    }

Usage Example

Example #1
0
 protected function loadExpectedMetadataFor($className, $type)
 {
     $expected = new ClassMetadata($className);
     $expected->type = $type;
     $expected->identifier = 'id';
     $expected->index = 'searchdemo';
     $expected->numberOfShards = 2;
     $expected->numberOfReplicas = 1;
     $expected->timeToLive = 180;
     $expected->boost = 2.0;
     $expected->source = true;
     $expected->mapRoot(array('fieldName' => 'dynamic_templates', 'id' => 'template_2', 'match' => 'description*', 'mapping' => array('type' => 'multi_field', 'fields' => array(array('fieldName' => '{name}', 'type' => 'string', 'includeInAll' => false), array('fieldName' => 'untouched', 'type' => 'string', 'index' => 'not_analyzed')))));
     $expected->mapRoot(array('fieldName' => 'date_detection', 'value' => 'false'));
     $expected->mapField(array('fieldName' => 'name', 'type' => 'string', 'includeInAll' => false, 'index' => 'no', 'boost' => 2.0));
     $expected->mapField(array('fieldName' => 'username', 'type' => 'multi_field', 'fields' => array(array('fieldName' => 'username', 'type' => 'string', 'includeInAll' => true, 'analyzer' => 'whitespace'), array('fieldName' => 'username.term', 'type' => 'string', 'includeInAll' => false, 'index' => 'not_analyzed'))));
     $expected->mapField(array('fieldName' => 'ip', 'type' => 'ip', 'includeInAll' => false, 'index' => 'no', 'store' => true, 'nullValue' => '127.0.0.1'));
     $expected->mapField(array('fieldName' => 'emails', 'type' => 'nested', 'properties' => array(array('fieldName' => 'email', 'type' => 'string', 'includeInAll' => false, 'index' => 'not_analyzed'), array('fieldName' => 'createdAt', 'type' => 'date'))));
     $expected->mapField(array('fieldName' => 'friends', 'type' => 'string', 'includeInAll' => false, 'index' => 'not_analyzed'));
     $expected->mapField(array('fieldName' => 'active', 'type' => 'boolean', 'nullValue' => false));
     $expected->mapParameter(array('parameterName' => '_routing', 'type' => 'string'));
     return $expected;
 }