TASK: Add a way to configure size for suggests

This commit is contained in:
Daniel Siepmann 2017-12-21 17:17:23 +01:00
parent 0307471cf6
commit 60221abd74
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
4 changed files with 26 additions and 2 deletions

View file

@ -39,4 +39,11 @@ interface SuggestRequestInterface
* @return string
*/
public function getField();
/**
* Returns the number of results.
*
* @return int
*/
public function getSize();
}

View file

@ -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;
}
}

View file

@ -238,6 +238,7 @@ class QueryFactory
'prefix' => $searchRequest->getSearchTerm(),
'completion' => [
'field' => $suggest->getField(),
'size' => $suggest->getSize(),
],
],
],

View file

@ -138,7 +138,8 @@ class SearchService
$searchRequest->addSuggest($this->objectManager->get(
SuggestRequest::class,
$identifier,
$suggestConfig['field']
$suggestConfig['field'],
$suggestConfig['size'] ?: 5
));
}
}