-
Notifications
You must be signed in to change notification settings - Fork 17
IBX-6620: Added image search criterions #284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7a7f26e
Added image search criterions
ciastektk 9657a4e
Added new indexes
ciastektk d0d6bbf
Set Image Field Type as searchable
ciastektk d1ba584
Added mime field to ezimage field type
ciastektk db371d5
[Tests] Fixed tests for Image field type
ciastektk b32b5e9
[Tests] Added integration test coverage for image criterions
ciastektk 94d4e03
Fixed deprecation
ciastektk fba6a08
Added method ensureImageFieldTypeIsSearchable to SearchServiceImageTest
ciastektk ad93151
Fixed ImageCompositeCriterion validation
ciastektk 03a0765
Update src/lib/FieldType/Image/Value.php
ciastektk 07d16be
[CI] Added temporary dev dependency on ibexa/solr
ciastektk 2993d3d
Fixed path for KERNEL_CLASS env in solr
ciastektk 2320f67
Added DATABASE_URL env in solr integration phpunit
ciastektk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/contracts/Repository/Values/Content/Query/Criterion/Image.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Image\FileSize; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Image\Height; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Image\MimeType; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Image\Orientation; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Image\Width; | ||
|
|
||
| /** | ||
| * @phpstan-import-type Range from \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Image\AbstractImageCompositeCriterion | ||
| * | ||
| * @phpstan-type ImageCriteria array{ | ||
| * mimeTypes?: string|array<string>, | ||
| * size?: Range, | ||
| * width?: Range, | ||
| * height?: Range, | ||
| * orientation?: string|array<string>, | ||
| * } | ||
| * | ||
| * @template-extends \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Image\AbstractImageCompositeCriterion<ImageCriteria> | ||
| */ | ||
| final class Image extends Criterion\Image\AbstractImageCompositeCriterion | ||
| { | ||
| public const IMAGE_SEARCH_CRITERIA = [ | ||
| 'mimeTypes', | ||
| 'size', | ||
| 'width', | ||
| 'height', | ||
| 'orientation', | ||
| ]; | ||
|
|
||
| protected function getSupportedCriteria(): array | ||
| { | ||
| return self::IMAGE_SEARCH_CRITERIA; | ||
| } | ||
|
|
||
| /** | ||
| * @phpstan-param ImageCriteria $data | ||
| * | ||
| * @return array<\Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion> | ||
| * | ||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException | ||
| */ | ||
| protected function buildCriteria( | ||
| string $fieldDefIdentifier, | ||
| array $data | ||
| ): array { | ||
| $criteria = []; | ||
|
|
||
| if (isset($data['mimeTypes'])) { | ||
| $criteria[] = new MimeType( | ||
| $fieldDefIdentifier, | ||
| $data['mimeTypes'] | ||
| ); | ||
| } | ||
|
|
||
| if (isset($data['size'])) { | ||
| $size = $data['size']; | ||
| $criteria[] = new FileSize( | ||
| $fieldDefIdentifier, | ||
| $this->getMinValue($size), | ||
| $this->getMaxValue($size), | ||
| ); | ||
| } | ||
|
|
||
| if (isset($data['width'])) { | ||
| $width = $data['width']; | ||
| $criteria[] = new Width( | ||
| $fieldDefIdentifier, | ||
| $this->getMinValue($width), | ||
| $this->getMaxValue($width) | ||
| ); | ||
| } | ||
|
|
||
| if (isset($data['height'])) { | ||
| $height = $data['height']; | ||
| $criteria[] = new Height( | ||
| $fieldDefIdentifier, | ||
| $this->getMinValue($height), | ||
| $this->getMaxValue($height) | ||
| ); | ||
| } | ||
|
|
||
| if (isset($data['orientation'])) { | ||
| $criteria[] = new Orientation( | ||
| $fieldDefIdentifier, | ||
| $data['orientation'] | ||
| ); | ||
| } | ||
|
|
||
| return $criteria; | ||
| } | ||
| } |
108 changes: 108 additions & 0 deletions
108
...racts/Repository/Values/Content/Query/Criterion/Image/AbstractImageCompositeCriterion.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Image; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\CompositeCriterion; | ||
| use Ibexa\Core\Base\Exceptions\InvalidArgumentException; | ||
|
|
||
| /** | ||
| * @template TImageCriteria of array | ||
| * | ||
| * @phpstan-type Range array{ | ||
| * min?: int|null, | ||
| * max?: int|null, | ||
| * } | ||
| */ | ||
| abstract class AbstractImageCompositeCriterion extends CompositeCriterion | ||
| { | ||
| /** | ||
| * @phpstan-param TImageCriteria $data | ||
| * | ||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException | ||
| */ | ||
| public function __construct( | ||
| string $fieldDefIdentifier, | ||
| array $data | ||
| ) { | ||
| $this->validate($data, $this->getSupportedCriteria()); | ||
|
|
||
| $criteria = new Criterion\LogicalAnd( | ||
| $this->buildCriteria($fieldDefIdentifier, $data) | ||
| ); | ||
|
|
||
| parent::__construct($criteria); | ||
| } | ||
|
|
||
| /** | ||
| * @phpstan-param TImageCriteria $data | ||
| * | ||
| * @return array<\Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion> | ||
| */ | ||
| abstract protected function buildCriteria(string $fieldDefIdentifier, array $data): array; | ||
|
|
||
| /** | ||
| * @return array<string> | ||
| */ | ||
| abstract protected function getSupportedCriteria(): array; | ||
|
|
||
| /** | ||
| * @phpstan-param TImageCriteria $data | ||
| * | ||
| * @param array<string> $supportedCriteria | ||
| * | ||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException | ||
| */ | ||
| protected function validate( | ||
| array $data, | ||
| array $supportedCriteria | ||
| ): void { | ||
| if (empty($data)) { | ||
| throw new InvalidArgumentException( | ||
| '$data', | ||
| sprintf( | ||
| 'At least one of the supported criteria should be passed: "%s"', | ||
| implode(', ', $supportedCriteria) | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| $notSupportedCriteria = array_diff( | ||
| array_keys($data), | ||
| $supportedCriteria | ||
| ); | ||
|
|
||
| if (!empty($notSupportedCriteria)) { | ||
| throw new InvalidArgumentException( | ||
| '$data', | ||
| sprintf( | ||
| 'Given criteria are not supported: "%s". Supported image criteria: "%s"', | ||
| implode(', ', $notSupportedCriteria), | ||
| implode(', ', $supportedCriteria) | ||
| ) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param array{min?: int|null} $data | ||
| */ | ||
| protected function getMinValue(array $data): int | ||
| { | ||
| return $data['min'] ?? 0; | ||
| } | ||
|
|
||
| /** | ||
| * @param array{max?: int|null} $data | ||
| */ | ||
| protected function getMaxValue(array $data): ?int | ||
| { | ||
| return $data['max'] ?? null; | ||
| } | ||
| } | ||
93 changes: 93 additions & 0 deletions
93
...contracts/Repository/Values/Content/Query/Criterion/Image/AbstractImageRangeCriterion.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Image; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Operator; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Operator\Specifications; | ||
| use Ibexa\Core\Base\Exceptions\InvalidArgumentException; | ||
|
|
||
| abstract class AbstractImageRangeCriterion extends Criterion | ||
| { | ||
| /** | ||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException | ||
| */ | ||
| public function __construct( | ||
| string $fieldDefIdentifier, | ||
| int $minValue = 0, | ||
| ?int $maxValue = null | ||
| ) { | ||
| $this->validate($minValue, $maxValue); | ||
|
|
||
| $value[] = $minValue; | ||
| $operator = Operator::GTE; | ||
|
|
||
| if ($maxValue >= 1) { | ||
| $operator = Operator::BETWEEN; | ||
| $value[] = $maxValue; | ||
| } | ||
|
|
||
| parent::__construct( | ||
| $fieldDefIdentifier, | ||
| $operator, | ||
| $value | ||
| ); | ||
| } | ||
|
|
||
| public function getSpecifications(): array | ||
| { | ||
| return [ | ||
| new Specifications( | ||
| Operator::BETWEEN, | ||
| Specifications::FORMAT_ARRAY, | ||
| Specifications::TYPE_INTEGER | ||
| ), | ||
| new Specifications( | ||
| Operator::GTE, | ||
| Specifications::FORMAT_ARRAY, | ||
| Specifications::TYPE_INTEGER | ||
| ), | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException | ||
| */ | ||
| protected function validate( | ||
| int $minValue, | ||
| ?int $maxValue | ||
| ): void { | ||
| if ($minValue < 0) { | ||
| throw new InvalidArgumentException( | ||
| '$minValue', | ||
| 'Value should be grater or equal 0' | ||
| ); | ||
| } | ||
|
|
||
| if ( | ||
| null !== $maxValue | ||
| && $maxValue < 1 | ||
| ) { | ||
| throw new InvalidArgumentException( | ||
| '$maxValue', | ||
| 'Value should be grater or equal 1' | ||
| ); | ||
| } | ||
|
|
||
| if ( | ||
| null !== $maxValue | ||
| && $minValue > $maxValue | ||
| ) { | ||
| throw new InvalidArgumentException( | ||
| '$minValue', | ||
| 'Value should be grater than' . $maxValue | ||
| ); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.