diff --git a/src/lib/FieldType/Image/SearchField.php b/src/lib/FieldType/Image/SearchField.php index 40f3904c04..7ec05df1bd 100644 --- a/src/lib/FieldType/Image/SearchField.php +++ b/src/lib/FieldType/Image/SearchField.php @@ -18,6 +18,9 @@ class SearchField implements Indexable { public function getIndexData(Field $field, FieldDefinition $fieldDefinition) { + $width = $field->value->data['width'] ?? null; + $height = $field->value->data['height'] ?? null; + return [ new Search\Field( 'filename', @@ -39,6 +42,21 @@ public function getIndexData(Field $field, FieldDefinition $fieldDefinition) $field->value->data['mime'] ?? null, new Search\FieldType\StringField() ), + new Search\Field( + 'width', + $width, + new Search\FieldType\IntegerField() + ), + new Search\Field( + 'height', + $height, + new Search\FieldType\IntegerField() + ), + new Search\Field( + 'orientation', + $this->getOrientation($width, $height), + new Search\FieldType\StringField() + ), ]; } @@ -49,6 +67,9 @@ public function getIndexDefinition() 'alternative_text' => new Search\FieldType\StringField(), 'file_size' => new Search\FieldType\IntegerField(), 'mime_type' => new Search\FieldType\StringField(), + 'width' => new Search\FieldType\IntegerField(), + 'height' => new Search\FieldType\IntegerField(), + 'orientation' => new Search\FieldType\StringField(), ]; } @@ -79,6 +100,23 @@ public function getDefaultSortField() { return $this->getDefaultMatchField(); } + + private function getOrientation( + ?int $width, + ?int $height + ): ?string { + if (null === $width || null === $height) { + return null; + } + + if ($width === $height) { + return Orientation::SQUARE; + } + + return $width > $height + ? Orientation::LANDSCAPE + : Orientation::PORTRAIT; + } } class_alias(SearchField::class, 'eZ\Publish\Core\FieldType\Image\SearchField');