Example #1
0
 /**
  * Get field type information for sort clause
  *
  * TODO: handle custom field
  * TODO: caching (see above)
  *
  * @param string $contentTypeIdentifier
  * @param string $fieldDefinitionIdentifier
  * @param string $languageCode
  *
  * @return array
  */
 public function getSortFieldTypes($contentTypeIdentifier, $fieldDefinitionIdentifier, $languageCode)
 {
     $types = array();
     foreach ($this->contentTypeHandler->loadAllGroups() as $group) {
         foreach ($this->contentTypeHandler->loadContentTypes($group->id) as $contentType) {
             if ($contentType->identifier !== $contentTypeIdentifier) {
                 continue;
             }
             foreach ($contentType->fieldDefinitions as $fieldDefinition) {
                 if ($fieldDefinition->identifier !== $fieldDefinitionIdentifier) {
                     continue;
                 }
                 // TODO: find a better way to handle non-translatable fields?
                 if ($languageCode === null || $fieldDefinition->isTranslatable) {
                     $fieldType = $this->fieldRegistry->getType($fieldDefinition->fieldType);
                     foreach ($fieldType->getIndexDefinition() as $name => $type) {
                         $types[$type->type] = $this->nameGenerator->getTypedName($this->nameGenerator->getName($name, $fieldDefinition->identifier, $contentType->identifier), $type);
                     }
                 }
                 break 3;
             }
         }
     }
     return $types;
 }
Example #2
0
 /**
  * Returns an array of documents containing fields for the given $content.
  * Each document contains fields for a single language.
  *
  * @param \eZ\Publish\SPI\Persistence\Content $content
  * @param \eZ\Publish\SPI\Persistence\Content\Type $contentType
  *
  * @return \eZ\Publish\Core\Persistence\Elasticsearch\Content\Search\Document[]
  */
 protected function mapFields(Content $content, Type $contentType)
 {
     $fieldMap = array();
     foreach ($content->fields as $field) {
         $fieldMap[$field->languageCode][] = $field;
     }
     $fieldDocuments = array();
     foreach (array_keys($fieldMap) as $languageCode) {
         $fields = array();
         $fields[] = new Field('meta_language_code', $languageCode, new FieldType\StringField());
         $fields[] = new Field('meta_is_main_translation', $content->versionInfo->contentInfo->mainLanguageCode === $languageCode, new FieldType\BooleanField());
         $fields[] = new Field('meta_is_always_available', $content->versionInfo->contentInfo->mainLanguageCode === $languageCode && $content->versionInfo->contentInfo->alwaysAvailable, new FieldType\BooleanField());
         foreach ($fieldMap[$languageCode] as $field) {
             foreach ($contentType->fieldDefinitions as $fieldDefinition) {
                 if ($fieldDefinition->id !== $field->fieldDefinitionId) {
                     continue;
                 }
                 $fieldType = $this->fieldRegistry->getType($field->type);
                 foreach ($fieldType->getIndexData($field) as $indexField) {
                     $fields[] = new Field($name = $this->fieldNameGenerator->getName($indexField->name, $fieldDefinition->identifier, $contentType->identifier), $indexField->value, $indexField->type);
                     if ($indexField->type instanceof FieldType\StringField || $indexField->type instanceof FieldType\MultipleStringField) {
                         $fields[] = new Field($name . "_meta_all_" . str_replace("-", "_", $languageCode), $indexField->value, $indexField->type);
                     }
                 }
             }
         }
         $fieldDocuments[] = new Document(array("fields" => $fields));
     }
     return $fieldDocuments;
 }
Example #3
0
 /**
  * Map content to document.
  *
  * A document is an array of fields
  *
  * @param \eZ\Publish\SPI\Persistence\Content $content
  *
  * @return array
  */
 protected function mapContent(Content $content)
 {
     $locations = $this->locationHandler->loadLocationsByContent($content->versionInfo->contentInfo->id);
     $mainLocation = null;
     foreach ($locations as $location) {
         if ($location->id == $content->versionInfo->contentInfo->mainLocationId) {
             $mainLocation = $location;
         }
     }
     $section = $this->sectionHandler->load($content->versionInfo->contentInfo->sectionId);
     // UserGroups and Users are Content, but permissions cascade is achieved through
     // Locations hierarchy. We index all ancestor Location Content ids of all
     // Locations of an owner.
     $ancestorLocationsContentIds = $this->getAncestorLocationsContentIds($content->versionInfo->contentInfo->ownerId);
     // Add owner user id as it can also be considered as user group.
     $ancestorLocationsContentIds[] = $content->versionInfo->contentInfo->ownerId;
     $document = array(new Field('id', $content->versionInfo->contentInfo->id, new FieldType\IdentifierField()), new Field('type', $content->versionInfo->contentInfo->contentTypeId, new FieldType\IdentifierField()), new Field('version', $content->versionInfo->versionNo, new FieldType\IdentifierField()), new Field('status', $content->versionInfo->status, new FieldType\IdentifierField()), new Field('name', $content->versionInfo->contentInfo->name, new FieldType\StringField()), new Field('creator', $content->versionInfo->creatorId, new FieldType\IdentifierField()), new Field('owner', $content->versionInfo->contentInfo->ownerId, new FieldType\IdentifierField()), new Field('owner_user_group', $ancestorLocationsContentIds, new FieldType\MultipleIdentifierField()), new Field('section', $content->versionInfo->contentInfo->sectionId, new FieldType\IdentifierField()), new Field('section_identifier', $section->identifier, new FieldType\IdentifierField()), new Field('section_name', $section->name, new FieldType\StringField()), new Field('remote_id', $content->versionInfo->contentInfo->remoteId, new FieldType\IdentifierField()), new Field('modified', $content->versionInfo->contentInfo->modificationDate, new FieldType\DateField()), new Field('published', $content->versionInfo->contentInfo->publicationDate, new FieldType\DateField()), new Field('path', array_map(function ($location) {
         return $location->pathString;
     }, $locations), new FieldType\MultipleIdentifierField()), new Field('location', array_map(function ($location) {
         return $location->id;
     }, $locations), new FieldType\MultipleIdentifierField()), new Field('depth', array_map(function ($location) {
         return $location->depth;
     }, $locations), new FieldType\IntegerField()), new Field('priority', array_map(function ($location) {
         return $location->priority;
     }, $locations), new FieldType\IntegerField()), new Field('location_parent', array_map(function ($location) {
         return $location->parentId;
     }, $locations), new FieldType\MultipleIdentifierField()), new Field('location_remote_id', array_map(function ($location) {
         return $location->remoteId;
     }, $locations), new FieldType\MultipleIdentifierField()), new Field('language_code', array_keys($content->versionInfo->names), new FieldType\MultipleStringField()), new Field('main_language_code', $content->versionInfo->contentInfo->mainLanguageCode, new FieldType\StringField()), new Field('invisible', array_map(function ($location) {
         return $location->invisible;
     }, $locations), new FieldType\MultipleBooleanField()), new Field('always_available', $content->versionInfo->contentInfo->alwaysAvailable, new FieldType\BooleanField()));
     if ($mainLocation !== null) {
         $document[] = new Field('main_location', $mainLocation->id, new FieldType\IdentifierField());
         $document[] = new Field('main_location_parent', $mainLocation->parentId, new FieldType\IdentifierField());
         $document[] = new Field('main_location_remote_id', $mainLocation->remoteId, new FieldType\IdentifierField());
         $document[] = new Field('main_path', $mainLocation->pathString, new FieldType\IdentifierField());
         $document[] = new Field('main_depth', $mainLocation->depth, new FieldType\IntegerField());
         $document[] = new Field('main_priority', $mainLocation->priority, new FieldType\IntegerField());
     }
     $contentType = $this->contentTypeHandler->load($content->versionInfo->contentInfo->contentTypeId);
     $document[] = new Field('group', $contentType->groupIds, new FieldType\MultipleIdentifierField());
     foreach ($content->fields as $field) {
         foreach ($contentType->fieldDefinitions as $fieldDefinition) {
             if ($fieldDefinition->id !== $field->fieldDefinitionId) {
                 continue;
             }
             $fieldType = $this->fieldRegistry->getType($field->type);
             foreach ($fieldType->getIndexData($field) as $indexField) {
                 $document[] = new Field($this->fieldNameGenerator->getName($indexField->name, $fieldDefinition->identifier, $contentType->identifier), $indexField->value, $indexField->type);
             }
         }
     }
     $objectStateIds = array();
     foreach ($this->objectStateHandler->loadAllGroups() as $objectStateGroup) {
         $objectStateIds[] = $this->objectStateHandler->getContentState($content->versionInfo->contentInfo->id, $objectStateGroup->id)->id;
     }
     $document[] = new Field('object_state', $objectStateIds, new FieldType\MultipleIdentifierField());
     return $document;
 }
Example #4
0
 /**
  * Get field type information
  *
  * Returns an array in the form:
  *
  * <code>
  *  array(
  *      "field-identifier" => array(
  *          "solr_field_name",
  *          …
  *      ),
  *      …
  *  )
  * </code>
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Query\CustomFieldInterface $criterion
  *
  * @return array
  */
 public function getFieldTypes(CustomFieldInterface $criterion)
 {
     // @TODO: temp fixed by disabling caching, see https://jira.ez.no/browse/EZP-22834
     $this->fieldTypes = array();
     foreach ($this->contentTypeHandler->loadAllGroups() as $group) {
         foreach ($this->contentTypeHandler->loadContentTypes($group->id) as $contentType) {
             foreach ($contentType->fieldDefinitions as $fieldDefinition) {
                 if (!$fieldDefinition->isSearchable) {
                     continue;
                 }
                 if ($customField = $criterion->getCustomField($contentType->identifier, $fieldDefinition->identifier)) {
                     $this->fieldTypes[$fieldDefinition->identifier]["custom"][] = $customField;
                     continue;
                 }
                 $fieldType = $this->fieldRegistry->getType($fieldDefinition->fieldType);
                 foreach ($fieldType->getIndexDefinition() as $name => $type) {
                     $this->fieldTypes[$fieldDefinition->identifier][$type->type][] = $this->nameGenerator->getTypedName($this->nameGenerator->getName($name, $fieldDefinition->identifier, $contentType->identifier), $type);
                 }
             }
         }
     }
     return $this->fieldTypes;
 }