-
Notifications
You must be signed in to change notification settings - Fork 0
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
Co-authored-by: Krzysztof Słomka <[email protected]> Co-authored-by: Paweł Niedzielski <[email protected]> Co-authored-by: Mikolaj Adamczyk <[email protected]>
- Loading branch information
1 parent
9b1fb5e
commit 32becdd
Showing
43 changed files
with
1,847 additions
and
26 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
50 changes: 50 additions & 0 deletions
50
src/bundle/ArgumentResolver/SuggestionQueryArgumentResolver.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,50 @@ | ||
<?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\Bundle\Search\ArgumentResolver; | ||
|
||
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; | ||
use Ibexa\Search\Model\SuggestionQuery; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface; | ||
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; | ||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; | ||
|
||
final class SuggestionQueryArgumentResolver implements ArgumentValueResolverInterface | ||
{ | ||
private ConfigResolverInterface $configResolver; | ||
|
||
public function __construct(ConfigResolverInterface $configResolver) | ||
{ | ||
$this->configResolver = $configResolver; | ||
} | ||
|
||
public function supports(Request $request, ArgumentMetadata $argument): bool | ||
{ | ||
return SuggestionQuery::class === $argument->getType(); | ||
} | ||
|
||
/** | ||
* @return iterable<\Ibexa\Search\Model\SuggestionQuery> | ||
* | ||
* @throw \Symfony\Component\HttpKernel\Exception\BadRequestHttpException | ||
*/ | ||
public function resolve(Request $request, ArgumentMetadata $argument): iterable | ||
{ | ||
$defaultLimit = $this->configResolver->getParameter('search.suggestion.result_limit'); | ||
$query = $request->query->get('query'); | ||
$limit = $request->query->getInt('limit', $defaultLimit); | ||
$language = $request->query->get('language'); | ||
|
||
if ($query === null) { | ||
throw new BadRequestHttpException('Missing query parameter'); | ||
} | ||
|
||
yield new SuggestionQuery($query, $limit, $language); | ||
} | ||
} |
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\Bundle\Search\Controller; | ||
|
||
use Ibexa\Search\Model\SuggestionQuery; | ||
use Ibexa\Search\Service\SuggestionService; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
|
||
final class SuggestionController extends AbstractController | ||
{ | ||
private SuggestionService $suggestionService; | ||
|
||
public function __construct( | ||
SuggestionService $suggestionService | ||
) { | ||
$this->suggestionService = $suggestionService; | ||
} | ||
|
||
public function suggestAction(SuggestionQuery $suggestionQuery): JsonResponse | ||
{ | ||
$result = $this->suggestionService->suggest($suggestionQuery); | ||
|
||
return $this->json($result); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
src/bundle/DependencyInjection/Configuration/Parser/SiteAccessAware/SuggestionParser.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,104 @@ | ||
<?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\Bundle\Search\DependencyInjection\Configuration\Parser\SiteAccessAware; | ||
|
||
use Ibexa\Bundle\Core\DependencyInjection\Configuration\AbstractParser; | ||
use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\NodeBuilder; | ||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
|
||
/** | ||
* Configuration parser for search. | ||
* | ||
* @Example configuration: | ||
* | ||
* ```yaml | ||
* ibexa: | ||
* system: | ||
* default: # configuration per siteaccess or siteaccess group | ||
* search: | ||
* suggestion: | ||
* min_query_length: 3 | ||
* result_limit: 5 | ||
* ``` | ||
*/ | ||
final class SuggestionParser extends AbstractParser | ||
{ | ||
/** | ||
* @param array<string, mixed> $scopeSettings | ||
*/ | ||
public function mapConfig( | ||
array &$scopeSettings, | ||
$currentScope, | ||
ContextualizerInterface $contextualizer | ||
): void { | ||
if (empty($scopeSettings['search'])) { | ||
return; | ||
} | ||
|
||
$settings = $scopeSettings['search']; | ||
|
||
$this->addSuggestionParameters($settings, $currentScope, $contextualizer); | ||
} | ||
|
||
public function addSemanticConfig(NodeBuilder $nodeBuilder): void | ||
{ | ||
$rootProductCatalogNode = $nodeBuilder->arrayNode('search'); | ||
$rootProductCatalogNode->append($this->addSuggestionConfiguration()); | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $settings | ||
*/ | ||
private function addSuggestionParameters( | ||
array $settings, | ||
string $currentScope, | ||
ContextualizerInterface $contextualizer | ||
): void { | ||
$names = [ | ||
'min_query_length', | ||
'result_limit', | ||
]; | ||
|
||
foreach ($names as $name) { | ||
if (isset($settings['suggestion'][$name])) { | ||
$contextualizer->setContextualParameter( | ||
'search.suggestion.' . $name, | ||
$currentScope, | ||
$settings['suggestion'][$name] | ||
); | ||
} | ||
} | ||
} | ||
|
||
private function addSuggestionConfiguration(): ArrayNodeDefinition | ||
{ | ||
$treeBuilder = new TreeBuilder('suggestion'); | ||
$node = $treeBuilder->getRootNode(); | ||
|
||
$node | ||
->children() | ||
->integerNode('min_query_length') | ||
->info('The minimum length of the query string needed to trigger suggestions. Minimum value is 3.') | ||
->isRequired() | ||
->defaultValue(3) | ||
->min(3) | ||
->end() | ||
->integerNode('result_limit') | ||
->info('The maximum number of suggestion results to return. Minimum value is 5.') | ||
->isRequired() | ||
->defaultValue(5) | ||
->min(5) | ||
->end() | ||
->end(); | ||
|
||
return $node; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
ibexa.search: | ||
path: /search | ||
methods: ['GET'] | ||
defaults: | ||
_controller: 'Ibexa\Bundle\Search\Controller\SearchController::searchAction' | ||
methods: [GET] | ||
controller: 'Ibexa\Bundle\Search\Controller\SearchController::searchAction' | ||
|
||
ibexa.search.suggestion: | ||
path: /suggestion | ||
methods: [GET] | ||
controller: 'Ibexa\Bundle\Search\Controller\SuggestionController::suggestAction' | ||
options: | ||
expose: true |
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 |
---|---|---|
@@ -1,25 +1,32 @@ | ||
imports: | ||
- { resource: forms.yaml } | ||
- { resource: twig.yaml } | ||
- { resource: sorting_definitions.yaml } | ||
- { resource: views.yaml } | ||
- { resource: forms.yaml } | ||
- { resource: twig.yaml } | ||
- { resource: sorting_definitions.yaml } | ||
- { resource: views.yaml } | ||
- { resource: services/suggestions.yaml } | ||
- { resource: services/normalizers.yaml } | ||
|
||
services: | ||
_defaults: | ||
autoconfigure: true | ||
autowire: true | ||
public: false | ||
_defaults: | ||
autoconfigure: true | ||
autowire: true | ||
public: false | ||
|
||
Ibexa\Bundle\Search\Controller\SearchController: | ||
tags: | ||
- controller.service_arguments | ||
Ibexa\Bundle\Search\Controller\: | ||
resource: './../../Controller' | ||
tags: | ||
- controller.service_arguments | ||
|
||
Ibexa\Search\Mapper\PagerSearchContentToDataMapper: | ||
arguments: | ||
$contentTypeService: '@ibexa.api.service.content_type' | ||
$userService: '@ibexa.api.service.user' | ||
$userLanguagePreferenceProvider: '@Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProvider' | ||
$translationHelper: '@Ibexa\Core\Helper\TranslationHelper' | ||
$languageService: '@ibexa.api.service.language' | ||
Ibexa\Bundle\Search\Controller\SuggestionController: | ||
tags: | ||
- { name: 'container.service_subscriber', key: 'serializer', id: 'ibexa.search.suggestion.serializer' } | ||
|
||
Ibexa\Search\QueryType\SearchQueryType: ~ | ||
Ibexa\Search\Mapper\PagerSearchContentToDataMapper: | ||
arguments: | ||
$contentTypeService: '@ibexa.api.service.content_type' | ||
$userService: '@ibexa.api.service.user' | ||
$userLanguagePreferenceProvider: '@Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProvider' | ||
$translationHelper: '@Ibexa\Core\Helper\TranslationHelper' | ||
$languageService: '@ibexa.api.service.language' | ||
|
||
Ibexa\Search\QueryType\SearchQueryType: ~ |
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,25 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
ibexa.search.suggestion.serializer: | ||
class: Symfony\Component\Serializer\Serializer | ||
autoconfigure: false | ||
arguments: | ||
$normalizers: | ||
- '@Ibexa\Search\Serializer\Normalizer\Suggestion\ContentSuggestionNormalizer' | ||
- '@Ibexa\Search\Serializer\Normalizer\Suggestion\LocationNormalizer' | ||
- '@Ibexa\Search\Serializer\Normalizer\Suggestion\ParentLocationCollectionNormalizer' | ||
$encoders: | ||
- '@serializer.encoder.json' | ||
|
||
Ibexa\Search\Serializer\Normalizer\Suggestion\ContentSuggestionNormalizer: | ||
autoconfigure: false | ||
|
||
Ibexa\Search\Serializer\Normalizer\Suggestion\ParentLocationCollectionNormalizer: | ||
autoconfigure: false | ||
|
||
Ibexa\Search\Serializer\Normalizer\Suggestion\LocationNormalizer: | ||
autoconfigure: 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,26 @@ | ||
services: | ||
_defaults: | ||
autoconfigure: true | ||
autowire: true | ||
public: false | ||
|
||
Ibexa\Bundle\Search\ArgumentResolver\SuggestionQueryArgumentResolver: | ||
tags: | ||
- { name: 'controller.argument_value_resolver' } | ||
|
||
Ibexa\Search\EventDispatcher\EventListener\ContentSuggestionSubscriber: ~ | ||
|
||
Ibexa\Search\Mapper\SearchHitToContentSuggestionMapper: ~ | ||
|
||
Ibexa\Contracts\Search\Mapper\SearchHitToContentSuggestionMapperInterface: '@Ibexa\Search\Mapper\SearchHitToContentSuggestionMapper' | ||
|
||
Ibexa\Search\Service\SuggestionService: ~ | ||
|
||
Ibexa\Contracts\Search\Service\SuggestionServiceInterface: '@Ibexa\Search\Service\SuggestionService' | ||
|
||
Ibexa\Search\Service\Event\SuggestionService: | ||
decorates: Ibexa\Contracts\Search\Service\SuggestionServiceInterface | ||
|
||
Ibexa\Search\Provider\ParentLocationProvider: ~ | ||
|
||
Ibexa\Contracts\Search\Provider\ParentLocationProviderInterface: '@Ibexa\Search\Provider\ParentLocationProvider' |
Oops, something went wrong.