Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\DSL\Suggester;
/**
* Term class.
*/
class Term extends AbstractSuggester
{
const SORT_BY_SCORE = 'score';
const SORT_BY_FREQ = 'frequency';
const SUGGEST_MODE_MISSING = 'missing';
const SUGGEST_MODE_POPULAR = 'popular';
const SUGGEST_MODE_ALWAYS = 'always';
/**
* @var string
*/
private $sort;
/**
* @var string
*/
private $analyzer;
/**
* @var string;
*/
private $suggestMode;
/**
* @var int
*/
private $size;
/**
* @return string
*/
public function getType()
{
return 'term';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
if (!$this->getField() && !$this->getText()) {
throw new \LogicException('Field and text should be defined.');
}
$suggester = array_filter(
[
'field' => $this->getField(),
'analyzer' => $this->getAnalyzer(),
'sort' => $this->getSort(),
'suggest_mode' => $this->getSuggestMode(),
]
);
return [
$this->getName() => array_filter(
[
'text' => $this->getText(),
'size' => $this->getSize(),
'term' => $suggester,
]
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
];
}
/**
* @return string
*/
public function getSort()
{
return $this->sort;
}
/**
* @param string $sort
*
* @return Term
*/
public function setSort($sort)
{
if (in_array(
$sort,
[
self::SORT_BY_FREQ,
self::SORT_BY_SCORE,
]
)
) {
$this->sort = $sort;
}
return $this;
}
/**
* @return string
*/
public function getAnalyzer()
{
return $this->analyzer;
}
/**
* @param string $analyzer
*
* @return Term
*/
public function setAnalyzer($analyzer)
{
$this->analyzer = $analyzer;
return $this;
}
/**
* @return string
*/
public function getSuggestMode()
{
return $this->suggestMode;
}
/**
* @param string $suggestMode
*
* @return Term
*/
public function setSuggestMode($suggestMode)
{
if (in_array(
$suggestMode,
[
self::SUGGEST_MODE_ALWAYS,
self::SUGGEST_MODE_MISSING,
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
]
)
) {
$this->suggestMode = $suggestMode;
}
return $this;
}
/**
* @param int $size
*
* @return Term
*/
public function setSize($size)
{
$this->size = $size;
return $this;
}
/**
* @return int
*/
public function getSize()
{
return $this->size;
}
}