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 | |
Результат | string |
/** * 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]]; }
protected function writeField(XmlWriter $xmlWriter, Field $field) { foreach ((array) $this->fieldValueMapper->map($field) as $value) { $xmlWriter->startElement('field'); $xmlWriter->writeAttribute('name', $this->nameGenerator->getTypedName($field->name, $field->type)); $xmlWriter->text($value); $xmlWriter->endElement(); } }
/** * Converts given $document to a hash format that can be JSON encoded * to get a document _source. * * Implemented in a separate method because of a recursion needed to * handle nested documents. * * @param \eZ\Publish\Core\Search\Elasticsearch\Content\Document $document * * @return array */ protected function getDocumentHash(Document $document) { $hash = array(); foreach ($document->fields as $field) { if ($field->type instanceof DocumentField) { $documents = $this->fieldValueMapper->map($field); $values = array(); foreach ($documents as $document) { $values[] = $this->getDocumentHash($document); } } else { $values = (array) $this->fieldValueMapper->map($field); } $name = $this->nameGenerator->getTypedName($field->name, $field->type); if (count($values) === 1) { $hash[$name] = reset($values); } else { $hash[$name] = $values; } } return $hash; }