-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handled different coverage of field criteria across search engines
The Legacy and Solr search engines don't support the same fields as field criteria. This delegates checking for that to SearchFeature objects specialized depending on the engine type.
- Loading branch information
Bertrand Dunogier
committed
Jan 24, 2019
1 parent
6a6073f
commit c851ec1
Showing
6 changed files
with
189 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
namespace EzSystems\EzPlatformGraphQL\DependencyInjection\Factory; | ||
|
||
use eZ\Bundle\EzPublishCoreBundle\ApiLoader\RepositoryConfigurationProvider; | ||
|
||
class SearchFeaturesFactory | ||
{ | ||
/** | ||
* @var \eZ\Bundle\EzPublishCoreBundle\ApiLoader\RepositoryConfigurationProvider | ||
*/ | ||
private $configurationProvider; | ||
|
||
/** | ||
* @var \EzSystems\EzPlatformGraphQL\Search\SearchFeatures[] | ||
*/ | ||
private $searchFeatures = []; | ||
|
||
public function __construct(RepositoryConfigurationProvider $configurationProvider, array $searchFeatures) | ||
{ | ||
$this->configurationProvider = $configurationProvider; | ||
$this->searchFeatures = $searchFeatures; | ||
} | ||
|
||
public function build() | ||
{ | ||
$searchEngine = $this->configurationProvider->getRepositoryConfig()['search']['engine']; | ||
|
||
if (isset($this->searchFeatures[$searchEngine])) { | ||
return $this->searchFeatures[$searchEngine]; | ||
} else { | ||
throw new \InvalidArgumentException("Search engine not found"); | ||
} | ||
} | ||
} |
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
87 changes: 87 additions & 0 deletions
87
src/Schema/Domain/Content/Worker/FieldDefinition/AddFieldDefinitionToCollectionFilters.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,87 @@ | ||
<?php | ||
namespace EzSystems\EzPlatformGraphQL\Schema\Domain\Content\Worker\FieldDefinition; | ||
|
||
use eZ\Publish\API\Repository\Values\ContentType\ContentType; | ||
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition; | ||
use EzSystems\EzPlatformGraphQL\Schema\Builder; | ||
use EzSystems\EzPlatformGraphQL\Schema\Domain\Content\Worker\BaseWorker; | ||
use EzSystems\EzPlatformGraphQL\Schema\Worker; | ||
use EzSystems\EzPlatformGraphQL\Search\SearchFeatures; | ||
|
||
/** | ||
* Adds the field definition, if it is searchable, as a filter on the type's collection. | ||
*/ | ||
class AddFieldDefinitionToCollectionFilters extends BaseWorker implements Worker | ||
{ | ||
/** | ||
* @var SearchFeatures | ||
*/ | ||
private $searchFeatures; | ||
|
||
public function __construct(SearchFeatures $searchFeatures) | ||
{ | ||
$this->searchFeatures = $searchFeatures; | ||
} | ||
|
||
public function work(Builder $schema, array $args) | ||
{ | ||
$domainGroupName = $this->getNameHelper()->domainGroupName($args['ContentTypeGroup']); | ||
$domainContentCollectionField = $this->getNameHelper()->domainContentCollectionField($args['ContentType']); | ||
$fieldDefinitionField = $this->getNameHelper()->fieldDefinitionField($args['FieldDefinition']); | ||
|
||
$schema->addFieldToType( | ||
$domainGroupName, | ||
new Builder\Input\Field( | ||
$domainContentCollectionField, | ||
$this->getFilterType($args['FieldDefinition']), | ||
['description' => 'Filter content based on the ' . $args['FieldDefinition']->identifier . ' field'] | ||
) | ||
); | ||
} | ||
|
||
public function canWork(Builder $schema, array $args) | ||
{ | ||
return | ||
isset($args['FieldDefinition']) | ||
&& $args['FieldDefinition'] instanceof FieldDefinition | ||
& isset($args['ContentType']) | ||
&& $args['ContentType'] instanceof ContentType | ||
&& $this->searchFeatures->supportsFieldCriterion($args['FieldDefinition']); | ||
} | ||
|
||
/** | ||
* @param ContentType $contentType | ||
* @return string | ||
*/ | ||
protected function getDomainContentName(ContentType $contentType): string | ||
{ | ||
return $this->getNameHelper()->domainContentName($contentType); | ||
} | ||
|
||
/** | ||
* @param FieldDefinition $fieldDefinition | ||
* @return string | ||
*/ | ||
protected function getFieldDefinitionField(FieldDefinition $fieldDefinition): string | ||
{ | ||
return $this->getNameHelper()->fieldDefinitionField($fieldDefinition); | ||
} | ||
|
||
private function isSearchable(FieldDefinition $fieldDefinition): bool | ||
{ | ||
return $fieldDefinition->isSearchable | ||
// should only be verified if legacy is the current search engine | ||
&& $this->converterRegistry->getConverter($fieldDefinition->fieldTypeIdentifier)->getIndexColumn() !== false; | ||
} | ||
|
||
private function getFilterType(FieldDefinition $fieldDefinition) | ||
{ | ||
switch ($fieldDefinition->fieldTypeIdentifier) | ||
{ | ||
case 'ezboolean': | ||
return 'Boolean'; | ||
default: | ||
return 'String'; | ||
} | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
namespace EzSystems\EzPlatformGraphQL\Search; | ||
|
||
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition; | ||
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry; | ||
|
||
class LegacySearchFeatures implements SearchFeatures | ||
{ | ||
/** | ||
* @var \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry | ||
*/ | ||
private $converterRegistry; | ||
|
||
public function __construct(ConverterRegistry $converterRegistry) | ||
{ | ||
$this->converterRegistry = $converterRegistry; | ||
} | ||
|
||
public function supportsFieldCriterion(FieldDefinition $fieldDefinition) | ||
{ | ||
return $this->converterRegistry->getConverter($fieldDefinition->fieldTypeIdentifier)->getIndexColumn() !== false; | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
namespace EzSystems\EzPlatformGraphQL\Search; | ||
|
||
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition; | ||
|
||
interface SearchFeatures | ||
{ | ||
/** | ||
* Tests if search supports field filtering on $fieldDefinition. | ||
* | ||
* @param FieldDefinition $fieldDefinition | ||
* | ||
* @return bool | ||
*/ | ||
public function supportsFieldCriterion(FieldDefinition $fieldDefinition); | ||
} |
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,12 @@ | ||
<?php | ||
namespace EzSystems\EzPlatformGraphQL\Search; | ||
|
||
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition; | ||
|
||
class SolrSearchFeatures implements SearchFeatures | ||
{ | ||
public function supportsFieldCriterion(FieldDefinition $fieldDefinition) | ||
{ | ||
return true; | ||
} | ||
} |