From f9f9432648de08de1b138f7343a05e2deb1bd0cc Mon Sep 17 00:00:00 2001 From: Stefan Bofirov <stefan.bofirov@dnhsoft.com> Date: Wed, 3 Feb 2016 16:59:29 +0200 Subject: [PATCH] Use ParamatersTrait in Suggest --- src/Suggest/Suggest.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Suggest/Suggest.php b/src/Suggest/Suggest.php index ebf0b5f..fe70fb9 100644 --- a/src/Suggest/Suggest.php +++ b/src/Suggest/Suggest.php @@ -12,9 +12,12 @@ namespace ONGR\ElasticsearchDSL\Suggest; use ONGR\ElasticsearchDSL\BuilderInterface; +use ONGR\ElasticsearchDSL\ParametersTrait; class Suggest implements BuilderInterface { + use ParametersTrait; + const DEFAULT_SIZE = 3; /** @@ -27,16 +30,11 @@ class Suggest implements BuilderInterface */ private $text; - /** - * @var array - */ - private $params; - - public function __construct($name, $text, $params = []) + public function __construct($name, $text, $parameters = []) { $this->name = $name; $this->text = $text; - $this->params = $params; + $this->setParameters($parameters); } /** @@ -64,17 +62,17 @@ class Suggest implements BuilderInterface */ public function toArray() { - if (!isset($this->params['field'])) { - $this->params['field'] = '_all'; + if (!$this->hasParameter('field')) { + $this->addParameter('field', '_all'); } - if (!isset($this->params['size'])) { - $this->params['size'] = self::DEFAULT_SIZE; + if (!$this->hasParameter('size')) { + $this->addParameter('size', self::DEFAULT_SIZE); } $output = [ 'text' => $this->text, - 'term' => $this->params, + 'term' => $this->getParameters(), ]; return $output; -- GitLab