diff --git a/Classes/Connection/SuggestRequestInterface.php b/Classes/Connection/SuggestRequestInterface.php index 5a24127..58dfa19 100644 --- a/Classes/Connection/SuggestRequestInterface.php +++ b/Classes/Connection/SuggestRequestInterface.php @@ -39,4 +39,11 @@ interface SuggestRequestInterface * @return string */ public function getField(); + + /** + * Returns the number of results. + * + * @return int + */ + public function getSize(); } diff --git a/Classes/Domain/Model/SuggestRequest.php b/Classes/Domain/Model/SuggestRequest.php index 4ee1047..b7d7550 100644 --- a/Classes/Domain/Model/SuggestRequest.php +++ b/Classes/Domain/Model/SuggestRequest.php @@ -34,6 +34,11 @@ class SuggestRequest implements SuggestRequestInterface */ protected $field = ''; + /** + * @var int + */ + protected $size = 5; + /** * TODO: Add validation / exception? * As the suggests come from configuration this might be a good idea to @@ -41,11 +46,13 @@ class SuggestRequest implements SuggestRequestInterface * * @param string $identifier * @param string $field + * @param int $size */ - public function __construct($identifier, $field) + public function __construct($identifier, $field, $size) { $this->identifier = $identifier; $this->field = $field; + $this->size = (int) $size; } /** @@ -63,4 +70,12 @@ class SuggestRequest implements SuggestRequestInterface { return $this->field; } + + /** + * @return int + */ + public function getSize() + { + return $this->size; + } } diff --git a/Classes/Domain/Search/QueryFactory.php b/Classes/Domain/Search/QueryFactory.php index a19cc35..48802e1 100644 --- a/Classes/Domain/Search/QueryFactory.php +++ b/Classes/Domain/Search/QueryFactory.php @@ -238,6 +238,7 @@ class QueryFactory 'prefix' => $searchRequest->getSearchTerm(), 'completion' => [ 'field' => $suggest->getField(), + 'size' => $suggest->getSize(), ], ], ], diff --git a/Classes/Domain/Search/SearchService.php b/Classes/Domain/Search/SearchService.php index f5c13d6..fe3cde0 100644 --- a/Classes/Domain/Search/SearchService.php +++ b/Classes/Domain/Search/SearchService.php @@ -138,7 +138,8 @@ class SearchService $searchRequest->addSuggest($this->objectManager->get( SuggestRequest::class, $identifier, - $suggestConfig['field'] + $suggestConfig['field'], + $suggestConfig['size'] ?: 5 )); } }