Skip to content

Commit

Permalink
Added new indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Oct 19, 2023
1 parent 5618488 commit 74df401
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/lib/FieldType/Image/SearchField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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()
),
];
}

Expand All @@ -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(),
];
}

Expand Down Expand Up @@ -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');

0 comments on commit 74df401

Please sign in to comment.