diff --git a/config/services/controller.php b/config/services/controller.php index 168301d..45f14fc 100644 --- a/config/services/controller.php +++ b/config/services/controller.php @@ -15,6 +15,8 @@ $parameters = $containerConfigurator->parameters(); $parameters->set('webgriffe.sylius_elasticsearch_plugin.taxon_default_page_limit', 9); $parameters->set('webgriffe.sylius_elasticsearch_plugin.search_default_page_limit', 9); + $parameters->set('webgriffe.sylius_elasticsearch_plugin.instant_search_page_limit', 8); + $parameters->set('webgriffe.sylius_elasticsearch_plugin.instant_search_completion_suggesters_size', 5); $services = $containerConfigurator->services(); @@ -44,6 +46,8 @@ service('webgriffe.sylius_elasticsearch_plugin.provider.document_type'), service('webgriffe.sylius_elasticsearch_plugin.builder.query'), service('webgriffe.sylius_elasticsearch_plugin.mapper.query_result'), + param('webgriffe.sylius_elasticsearch_plugin.instant_search_page_limit'), + param('webgriffe.sylius_elasticsearch_plugin.instant_search_completion_suggesters_size'), ]) ->call('setContainer', [service('service_container')]) ->tag('controller.service_arguments') diff --git a/src/Builder/QueryBuilderInterface.php b/src/Builder/QueryBuilderInterface.php index 66e7f1c..f607652 100644 --- a/src/Builder/QueryBuilderInterface.php +++ b/src/Builder/QueryBuilderInterface.php @@ -43,6 +43,7 @@ public function buildSearchQuery( public function buildCompletionSuggestersQuery( string $searchTerm, ?string $source = 'suggest', + int $size = 5, ): array; public function buildTermSuggestersQuery( diff --git a/src/Builder/TwigQueryBuilder.php b/src/Builder/TwigQueryBuilder.php index 09f2a3d..fdf92da 100644 --- a/src/Builder/TwigQueryBuilder.php +++ b/src/Builder/TwigQueryBuilder.php @@ -189,11 +189,13 @@ public function buildSearchQuery( public function buildCompletionSuggestersQuery( string $searchTerm, ?string $source = 'suggest', + int $size = 5, ): array { $localeCode = $this->localeContext->getLocaleCode(); $query = $this->twig->render('@WebgriffeSyliusElasticsearchPlugin/query/completion-suggesters/query.json.twig', [ 'searchTerm' => $searchTerm, 'localeCode' => $localeCode, + 'size' => $size, ]); $completionSuggestersQuery = []; /** @var array $queryNormalized */ diff --git a/src/Controller/InstantSearchController.php b/src/Controller/InstantSearchController.php index 3493d07..837fe1a 100644 --- a/src/Controller/InstantSearchController.php +++ b/src/Controller/InstantSearchController.php @@ -24,6 +24,9 @@ */ final class InstantSearchController extends AbstractController implements InstantSearchControllerInterface { + /** + * @param int<1,10_000> $maxResults + */ public function __construct( private readonly ClientInterface $client, private readonly ChannelContextInterface $channelContext, @@ -31,6 +34,8 @@ public function __construct( private readonly DocumentTypeProviderInterface $documentTypeProvider, private readonly QueryBuilderInterface $queryBuilder, private readonly QueryResultMapperInterface $queryResultMapper, + private readonly int $maxResults, + private readonly int $completionSuggestersSize, ) { } @@ -48,12 +53,12 @@ public function __invoke(Request $request, string $query): Response } $completionSuggesters = $this->client->completionSuggesters( - $this->queryBuilder->buildCompletionSuggestersQuery($query), + $this->queryBuilder->buildCompletionSuggestersQuery($query, 'suggest', $this->completionSuggestersSize), $indexAliasNames, ); $esResult = $this->client->query( - $this->queryBuilder->buildSearchQuery($query), + $this->queryBuilder->buildSearchQuery($query, null, $this->maxResults), $indexAliasNames, ); $queryResult = $this->queryResultMapper->map($esResult); diff --git a/templates/query/completion-suggesters/query.json.twig b/templates/query/completion-suggesters/query.json.twig index ffc67f3..50c78ff 100644 --- a/templates/query/completion-suggesters/query.json.twig +++ b/templates/query/completion-suggesters/query.json.twig @@ -3,7 +3,7 @@ "prefix": "{{ searchTerm }}", "completion": { "field": "suggest", - "size": 5, + "size": {{ size }}, "skip_duplicates": true, "fuzzy": { "fuzziness": 1,