mirror of
https://github.com/Codappix/search_core.git
synced 2024-12-25 08:16:09 +01:00
TASK: Add a way to configure size for suggests
This commit is contained in:
parent
0307471cf6
commit
60221abd74
4 changed files with 26 additions and 2 deletions
|
@ -39,4 +39,11 @@ interface SuggestRequestInterface
|
|||
* @return string
|
||||
*/
|
||||
public function getField();
|
||||
|
||||
/**
|
||||
* Returns the number of results.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSize();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -238,6 +238,7 @@ class QueryFactory
|
|||
'prefix' => $searchRequest->getSearchTerm(),
|
||||
'completion' => [
|
||||
'field' => $suggest->getField(),
|
||||
'size' => $suggest->getSize(),
|
||||
],
|
||||
],
|
||||
],
|
||||
|
|
|
@ -138,7 +138,8 @@ class SearchService
|
|||
$searchRequest->addSuggest($this->objectManager->get(
|
||||
SuggestRequest::class,
|
||||
$identifier,
|
||||
$suggestConfig['field']
|
||||
$suggestConfig['field'],
|
||||
$suggestConfig['size'] ?: 5
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue