-
Notifications
You must be signed in to change notification settings - Fork 4
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
IBX-6620: Added Image criterion visitors #55
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
60fa18f
Added Image criterion visitors
ciastektk 717568e
[Tests] Added IbexaTestKernel
ciastektk 9c0cbad
[PHPStan] Regenerated baseline
ciastektk 0336594
Fixed deprecation notices
ciastektk 0bb09c9
Added exception throwing when searchFileNames array is empty
ciastektk 2012855
Fixed deprecation message
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 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 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 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,48 @@ | ||
<?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\Solr\Test; | ||
|
||
use Ibexa\Bundle\Solr\IbexaSolrBundle; | ||
use Ibexa\Contracts\Core\Search\Handler; | ||
use Ibexa\Contracts\Core\Test\IbexaTestKernel as BaseIbexaTestKernel; | ||
use Ibexa\Solr\Handler as SolrHandler; | ||
use Ibexa\Solr\Test\SolrTestContainerBuilder; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* @internal | ||
* | ||
* Exposed in contracts to be able to run tests from ibexa/core. | ||
*/ | ||
final class IbexaSolrTestKernel extends BaseIbexaTestKernel | ||
{ | ||
public function registerBundles(): iterable | ||
{ | ||
yield from parent::registerBundles(); | ||
|
||
yield new IbexaSolrBundle(); | ||
} | ||
|
||
protected static function getExposedServicesById(): iterable | ||
{ | ||
yield from parent::getExposedServicesById(); | ||
|
||
yield SolrHandler::class => Handler::class; | ||
} | ||
|
||
public function registerContainerConfiguration(LoaderInterface $loader): void | ||
{ | ||
parent::registerContainerConfiguration($loader); | ||
|
||
$loader->load(static function (ContainerBuilder $container): void { | ||
(new SolrTestContainerBuilder())->loadSolrSettings($container); | ||
}); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/lib/Query/Image/CriterionVisitor/AbstractImageRangeVisitor.php
This file contains 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,32 @@ | ||
<?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\Solr\Query\Image\CriterionVisitor; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
use Ibexa\Contracts\Solr\Query\CriterionVisitor; | ||
|
||
abstract class AbstractImageRangeVisitor extends AbstractImageVisitor | ||
{ | ||
public function visit(Criterion $criterion, CriterionVisitor $subVisitor = null): string | ||
{ | ||
/** @var array{0: int, 1?: int|null} $criterionValue */ | ||
$criterionValue = $criterion->value; | ||
$queries = []; | ||
|
||
foreach ($this->getSearchFieldNames($criterion) as $fieldName) { | ||
$queries[] = $fieldName . ':' . $this->getRange( | ||
$criterion->operator, | ||
$criterionValue[0], | ||
$criterionValue[1] ?? null | ||
); | ||
} | ||
|
||
return '(' . implode(' OR ', $queries) . ')'; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/lib/Query/Image/CriterionVisitor/AbstractImageTermsVisitor.php
This file contains 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,36 @@ | ||
<?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\Solr\Query\Image\CriterionVisitor; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
use Ibexa\Contracts\Solr\Query\CriterionVisitor; | ||
|
||
abstract class AbstractImageTermsVisitor extends AbstractImageVisitor | ||
{ | ||
public function visit(Criterion $criterion, CriterionVisitor $subVisitor = null): string | ||
{ | ||
$queries = []; | ||
/** @var array<string>|string $criterionValue */ | ||
$criterionValue = $criterion->value; | ||
|
||
foreach ($this->getSearchFieldNames($criterion) as $fieldName) { | ||
if (is_array($criterionValue)) { | ||
foreach ($criterionValue as $value) { | ||
$queries[] = $fieldName . ':' . $value; | ||
} | ||
} | ||
|
||
if (is_string($criterionValue)) { | ||
$queries[] = $fieldName . ':' . $criterionValue; | ||
} | ||
} | ||
|
||
return '(' . implode(' OR ', $queries) . ')'; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/lib/Query/Image/CriterionVisitor/AbstractImageVisitor.php
This file contains 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,58 @@ | ||
<?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\Solr\Query\Image\CriterionVisitor; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
use Ibexa\Contracts\Solr\Query\CriterionVisitor; | ||
use Ibexa\Core\Base\Exceptions\InvalidArgumentException; | ||
use Ibexa\Core\FieldType\Image\Type; | ||
use Ibexa\Core\Search\Common\FieldNameResolver; | ||
|
||
abstract class AbstractImageVisitor extends CriterionVisitor | ||
{ | ||
private FieldNameResolver $fieldNameResolver; | ||
|
||
private Type $imageFieldType; | ||
|
||
public function __construct( | ||
FieldNameResolver $fieldNameResolver, | ||
Type $imageFieldType | ||
) { | ||
$this->fieldNameResolver = $fieldNameResolver; | ||
$this->imageFieldType = $imageFieldType; | ||
} | ||
|
||
abstract protected function getSearchFieldName(): string; | ||
|
||
/** | ||
* @return array<string> | ||
* | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException | ||
*/ | ||
protected function getSearchFieldNames(Criterion $criterion): array | ||
{ | ||
$searchFieldNames = array_keys( | ||
$this->fieldNameResolver->getFieldTypes( | ||
$criterion, | ||
$criterion->target, | ||
$this->imageFieldType->getFieldTypeIdentifier(), | ||
$this->getSearchFieldName() | ||
) | ||
); | ||
|
||
if (empty($searchFieldNames)) { | ||
throw new InvalidArgumentException( | ||
'$criterion->target', | ||
"No searchable Fields found for the provided Criterion target '{$criterion->target}'." | ||
); | ||
} | ||
|
||
return $searchFieldNames; | ||
} | ||
} |
This file contains 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,31 @@ | ||
<?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\Solr\Query\Image\CriterionVisitor; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Operator; | ||
|
||
final class FileSize extends AbstractImageRangeVisitor | ||
{ | ||
private const SEARCH_FIELD_FILE_SIZE = 'file_size'; | ||
|
||
public function canVisit(Criterion $criterion): bool | ||
{ | ||
return $criterion instanceof Criterion\Image\FileSize | ||
&& ( | ||
$criterion->operator === Operator::BETWEEN | ||
|| $criterion->operator === Operator::GTE | ||
); | ||
} | ||
|
||
protected function getSearchFieldName(): string | ||
{ | ||
return self::SEARCH_FIELD_FILE_SIZE; | ||
} | ||
} |
This file contains 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,31 @@ | ||
<?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\Solr\Query\Image\CriterionVisitor; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Operator; | ||
|
||
final class Height extends AbstractImageRangeVisitor | ||
{ | ||
private const SEARCH_FIELD_HEIGHT = 'height'; | ||
|
||
public function canVisit(Criterion $criterion): bool | ||
{ | ||
return $criterion instanceof Criterion\Image\Height | ||
&& ( | ||
$criterion->operator === Operator::BETWEEN | ||
|| $criterion->operator === Operator::GTE | ||
); | ||
} | ||
|
||
protected function getSearchFieldName(): string | ||
{ | ||
return self::SEARCH_FIELD_HEIGHT; | ||
} | ||
} |
This file contains 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,31 @@ | ||
<?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\Solr\Query\Image\CriterionVisitor; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Operator; | ||
|
||
final class MimeType extends AbstractImageTermsVisitor | ||
{ | ||
private const SEARCH_FIELD_MIME_TYPE = 'mime_type'; | ||
|
||
public function canVisit(Criterion $criterion): bool | ||
{ | ||
return $criterion instanceof Criterion\Image\MimeType | ||
&& ( | ||
$criterion->operator === Operator::EQ | ||
|| $criterion->operator === Operator::IN | ||
); | ||
} | ||
|
||
protected function getSearchFieldName(): string | ||
{ | ||
return self::SEARCH_FIELD_MIME_TYPE; | ||
} | ||
} |
This file contains 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,31 @@ | ||
<?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\Solr\Query\Image\CriterionVisitor; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Operator; | ||
|
||
final class Orientation extends AbstractImageTermsVisitor | ||
{ | ||
private const SEARCH_FIELD_ORIENTATION = 'orientation'; | ||
|
||
public function canVisit(Criterion $criterion): bool | ||
{ | ||
return $criterion instanceof Criterion\Image\Orientation | ||
&& ( | ||
$criterion->operator === Operator::EQ | ||
|| $criterion->operator === Operator::IN | ||
); | ||
} | ||
|
||
protected function getSearchFieldName(): string | ||
{ | ||
return self::SEARCH_FIELD_ORIENTATION; | ||
} | ||
} |
This file contains 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,31 @@ | ||
<?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\Solr\Query\Image\CriterionVisitor; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Operator; | ||
|
||
final class Width extends AbstractImageRangeVisitor | ||
{ | ||
private const SEARCH_FIELD_WIDTH = 'width'; | ||
|
||
public function canVisit(Criterion $criterion): bool | ||
{ | ||
return $criterion instanceof Criterion\Image\Width | ||
&& ( | ||
$criterion->operator === Operator::BETWEEN | ||
|| $criterion->operator === Operator::GTE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same remark as for |
||
); | ||
} | ||
|
||
protected function getSearchFieldName(): string | ||
{ | ||
return self::SEARCH_FIELD_WIDTH; | ||
} | ||
} |
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't also make sense to have
Operator::LTE
here?