mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-23 20:56:10 +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
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getField();
|
public function getField();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of results.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getSize();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,11 @@ class SuggestRequest implements SuggestRequestInterface
|
||||||
*/
|
*/
|
||||||
protected $field = '';
|
protected $field = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $size = 5;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Add validation / exception?
|
* TODO: Add validation / exception?
|
||||||
* As the suggests come from configuration this might be a good idea to
|
* 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 $identifier
|
||||||
* @param string $field
|
* @param string $field
|
||||||
|
* @param int $size
|
||||||
*/
|
*/
|
||||||
public function __construct($identifier, $field)
|
public function __construct($identifier, $field, $size)
|
||||||
{
|
{
|
||||||
$this->identifier = $identifier;
|
$this->identifier = $identifier;
|
||||||
$this->field = $field;
|
$this->field = $field;
|
||||||
|
$this->size = (int) $size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,4 +70,12 @@ class SuggestRequest implements SuggestRequestInterface
|
||||||
{
|
{
|
||||||
return $this->field;
|
return $this->field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getSize()
|
||||||
|
{
|
||||||
|
return $this->size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,6 +238,7 @@ class QueryFactory
|
||||||
'prefix' => $searchRequest->getSearchTerm(),
|
'prefix' => $searchRequest->getSearchTerm(),
|
||||||
'completion' => [
|
'completion' => [
|
||||||
'field' => $suggest->getField(),
|
'field' => $suggest->getField(),
|
||||||
|
'size' => $suggest->getSize(),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
|
@ -138,7 +138,8 @@ class SearchService
|
||||||
$searchRequest->addSuggest($this->objectManager->get(
|
$searchRequest->addSuggest($this->objectManager->get(
|
||||||
SuggestRequest::class,
|
SuggestRequest::class,
|
||||||
$identifier,
|
$identifier,
|
||||||
$suggestConfig['field']
|
$suggestConfig['field'],
|
||||||
|
$suggestConfig['size'] ?: 5
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue