eZ\Publish\Core\Search\Elasticsearch\Content\Serializer::getDocumentHash PHP Method

getDocumentHash() protected method

Implemented in a separate method because of a recursion needed to handle nested documents.
protected getDocumentHash ( Document $document ) : array
$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;
    }