-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
15 changed files
with
447 additions
and
37 deletions.
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 | ||
); | ||
} | ||
|
||
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.