@@ 17-80 (lines=64) @@ | ||
14 | use ONGR\ElasticsearchDSL\BuilderInterface; |
|
15 | use ONGR\ElasticsearchDSL\ParametersTrait; |
|
16 | ||
17 | class PhraseSuggest implements BuilderInterface |
|
18 | { |
|
19 | use ParametersTrait; |
|
20 | ||
21 | const DEFAULT_SIZE = 3; |
|
22 | ||
23 | /** |
|
24 | * @var string |
|
25 | */ |
|
26 | private $name; |
|
27 | ||
28 | /** |
|
29 | * @var string |
|
30 | */ |
|
31 | private $text; |
|
32 | ||
33 | public function __construct($name, $text, $parameters = []) |
|
34 | { |
|
35 | $this->name = $name; |
|
36 | $this->text = $text; |
|
37 | $this->setParameters($parameters); |
|
38 | } |
|
39 | ||
40 | /** |
|
41 | * Returns element type. |
|
42 | * |
|
43 | * @return string |
|
44 | */ |
|
45 | public function getType() |
|
46 | { |
|
47 | return 'phrase_suggest'; |
|
48 | } |
|
49 | ||
50 | /** |
|
51 | * Returns suggest name |
|
52 | * |
|
53 | * @return string |
|
54 | */ |
|
55 | public function getName() |
|
56 | { |
|
57 | return $this->name; |
|
58 | } |
|
59 | ||
60 | /** |
|
61 | * {@inheritdoc} |
|
62 | */ |
|
63 | public function toArray() |
|
64 | { |
|
65 | if (!$this->hasParameter('field')) { |
|
66 | $this->addParameter('field', '_all'); |
|
67 | } |
|
68 | ||
69 | if (!$this->hasParameter('size')) { |
|
70 | $this->addParameter('size', self::DEFAULT_SIZE); |
|
71 | } |
|
72 | ||
73 | $output = [$this->name => [ |
|
74 | 'text' => $this->text, |
|
75 | 'phrase' => $this->getParameters(), |
|
76 | ]]; |
|
77 | ||
78 | return $output; |
|
79 | } |
|
80 | } |
|
81 |
@@ 17-80 (lines=64) @@ | ||
14 | use ONGR\ElasticsearchDSL\BuilderInterface; |
|
15 | use ONGR\ElasticsearchDSL\ParametersTrait; |
|
16 | ||
17 | class TermSuggest implements BuilderInterface |
|
18 | { |
|
19 | use ParametersTrait; |
|
20 | ||
21 | const DEFAULT_SIZE = 3; |
|
22 | ||
23 | /** |
|
24 | * @var string |
|
25 | */ |
|
26 | private $name; |
|
27 | ||
28 | /** |
|
29 | * @var string |
|
30 | */ |
|
31 | private $text; |
|
32 | ||
33 | public function __construct($name, $text, $parameters = []) |
|
34 | { |
|
35 | $this->name = $name; |
|
36 | $this->text = $text; |
|
37 | $this->setParameters($parameters); |
|
38 | } |
|
39 | ||
40 | /** |
|
41 | * Returns element type. |
|
42 | * |
|
43 | * @return string |
|
44 | */ |
|
45 | public function getType() |
|
46 | { |
|
47 | return 'term_suggest'; |
|
48 | } |
|
49 | ||
50 | /** |
|
51 | * Returns suggest name |
|
52 | * |
|
53 | * @return string |
|
54 | */ |
|
55 | public function getName() |
|
56 | { |
|
57 | return $this->name; |
|
58 | } |
|
59 | ||
60 | /** |
|
61 | * {@inheritdoc} |
|
62 | */ |
|
63 | public function toArray() |
|
64 | { |
|
65 | if (!$this->hasParameter('field')) { |
|
66 | $this->addParameter('field', '_all'); |
|
67 | } |
|
68 | ||
69 | if (!$this->hasParameter('size')) { |
|
70 | $this->addParameter('size', self::DEFAULT_SIZE); |
|
71 | } |
|
72 | ||
73 | $output = [$this->name => [ |
|
74 | 'text' => $this->text, |
|
75 | 'term' => $this->getParameters(), |
|
76 | ]]; |
|
77 | ||
78 | return $output; |
|
79 | } |
|
80 | } |
|
81 |