eZ\Publish\Core\Search\Common\FieldNameGenerator::getTypedName PHP Method

getTypedName() public method

For indexing backend the following scheme will always be used for names: {name}_{type}. Using dynamic fields this allows to define fields either depending on types, or names. Only the field with the name 'id' remains untouched.
public getTypedName ( string $name, eZ\Publish\SPI\Search\FieldType $type ) : string
$name string
$type eZ\Publish\SPI\Search\FieldType
return string
    public function getTypedName($name, FieldType $type)
    {
        if ($name === 'id') {
            return $name;
        }
        $typeName = $type->type;
        if (isset($this->fieldNameMapping[$typeName])) {
            $typeName = $this->fieldNameMapping[$typeName];
        }
        return $name . '_' . $typeName;
    }

Usage Example

 /**
  * Returns index field name for the given parameters.
  *
  * @param object $criterionOrSortClause
  * @param string $contentTypeIdentifier
  * @param string $fieldDefinitionIdentifier
  * @param string $fieldTypeIdentifier
  * @param string $name
  * @param bool $isSortField
  *
  * @return string
  */
 public function getIndexFieldName($criterionOrSortClause, $contentTypeIdentifier, $fieldDefinitionIdentifier, $fieldTypeIdentifier, $name, $isSortField)
 {
     // If criterion or sort clause implements CustomFieldInterface and custom field is set for
     // ContentType/FieldDefinition, return it
     if ($criterionOrSortClause instanceof CustomFieldInterface && ($customFieldName = $criterionOrSortClause->getCustomField($contentTypeIdentifier, $fieldDefinitionIdentifier))) {
         return [$customFieldName => null];
     }
     // Else, generate field name from field type's index definition
     $indexFieldType = $this->fieldRegistry->getType($fieldTypeIdentifier);
     // If $name is not given use default field name
     if ($name === null) {
         if ($isSortField) {
             $name = $indexFieldType->getDefaultSortField();
         } else {
             $name = $indexFieldType->getDefaultMatchField();
         }
     }
     $indexDefinition = $indexFieldType->getIndexDefinition();
     // Should only happen by mistake, so let's throw if it does
     if (!isset($indexDefinition[$name])) {
         throw new RuntimeException("Could not find '{$name}' field in '{$fieldTypeIdentifier}' field type's index definition");
     }
     $field = $this->nameGenerator->getTypedName($this->nameGenerator->getName($name, $fieldDefinitionIdentifier, $contentTypeIdentifier), $indexDefinition[$name]);
     return [$field => $indexDefinition[$name]];
 }
All Usage Examples Of eZ\Publish\Core\Search\Common\FieldNameGenerator::getTypedName