1 | <?php |
||
11 | class Helper |
||
12 | { |
||
13 | /** |
||
14 | * @var ConnectionInterface |
||
15 | */ |
||
16 | protected $connection; |
||
17 | |||
18 | /** |
||
19 | * @param ConnectionInterface $connection |
||
20 | */ |
||
21 | public function __construct(ConnectionInterface $connection) |
||
25 | |||
26 | /** |
||
27 | * Returns a new SphinxQL instance |
||
28 | * |
||
29 | * @return SphinxQL |
||
30 | */ |
||
31 | protected function getSphinxQL() |
||
35 | |||
36 | /** |
||
37 | * Prepares a query in SphinxQL (not executed) |
||
38 | * |
||
39 | * @param $sql |
||
40 | * |
||
41 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
42 | */ |
||
43 | protected function query($sql) |
||
47 | |||
48 | /** |
||
49 | * Converts the columns from queries like SHOW VARIABLES to simpler key-value |
||
50 | * |
||
51 | * @param array $result The result of an executed query |
||
52 | * |
||
53 | * @return array Associative array with Variable_name as key and Value as value |
||
54 | * @todo make non static |
||
55 | */ |
||
56 | public static function pairsToAssoc($result) |
||
66 | |||
67 | /** |
||
68 | * Runs query: SHOW META |
||
69 | * |
||
70 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
71 | */ |
||
72 | public function showMeta() |
||
76 | |||
77 | /** |
||
78 | * Runs query: SHOW WARNINGS |
||
79 | * |
||
80 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
81 | */ |
||
82 | public function showWarnings() |
||
86 | |||
87 | /** |
||
88 | * Runs query: SHOW STATUS |
||
89 | * |
||
90 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
91 | */ |
||
92 | public function showStatus() |
||
96 | |||
97 | /** |
||
98 | * Runs query: SHOW TABLES |
||
99 | * |
||
100 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
101 | */ |
||
102 | public function showTables() |
||
106 | |||
107 | /** |
||
108 | * Runs query: SHOW VARIABLES |
||
109 | * |
||
110 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
111 | */ |
||
112 | public function showVariables() |
||
116 | |||
117 | /** |
||
118 | * SET syntax |
||
119 | * |
||
120 | * @param string $name The name of the variable |
||
121 | * @param mixed $value The value of the variable |
||
122 | * @param boolean $global True if the variable should be global, false otherwise |
||
123 | * |
||
124 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
125 | */ |
||
126 | public function setVariable($name, $value, $global = false) |
||
149 | |||
150 | /** |
||
151 | * CALL SNIPPETS syntax |
||
152 | * |
||
153 | * @param string|array $data The document text (or documents) to search |
||
154 | * @param string $index |
||
155 | * @param string $query Search query used for highlighting |
||
156 | * @param array $options Associative array of additional options |
||
157 | * |
||
158 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
159 | */ |
||
160 | public function callSnippets($data, $index, $query, $options = array()) |
||
173 | |||
174 | /** |
||
175 | * CALL KEYWORDS syntax |
||
176 | * |
||
177 | * @param string $text |
||
178 | * @param string $index |
||
179 | * @param null|string $hits |
||
180 | * |
||
181 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
182 | */ |
||
183 | public function callKeywords($text, $index, $hits = null) |
||
192 | |||
193 | /** |
||
194 | * DESCRIBE syntax |
||
195 | * |
||
196 | * @param string $index The name of the index |
||
197 | * |
||
198 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
199 | */ |
||
200 | public function describe($index) |
||
204 | |||
205 | /** |
||
206 | * CREATE FUNCTION syntax |
||
207 | * |
||
208 | * @param string $udf_name |
||
209 | * @param string $returns Whether INT|BIGINT|FLOAT|STRING |
||
210 | * @param string $so_name |
||
211 | * |
||
212 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
213 | */ |
||
214 | public function createFunction($udf_name, $returns, $so_name) |
||
219 | |||
220 | /** |
||
221 | * DROP FUNCTION syntax |
||
222 | * |
||
223 | * @param string $udf_name |
||
224 | * |
||
225 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
226 | */ |
||
227 | public function dropFunction($udf_name) |
||
231 | |||
232 | /** |
||
233 | * ATTACH INDEX * TO RTINDEX * syntax |
||
234 | * |
||
235 | * @param string $disk_index |
||
236 | * @param string $rt_index |
||
237 | * |
||
238 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
239 | */ |
||
240 | public function attachIndex($disk_index, $rt_index) |
||
244 | |||
245 | /** |
||
246 | * FLUSH RTINDEX syntax |
||
247 | * |
||
248 | * @param string $index |
||
249 | * |
||
250 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
251 | */ |
||
252 | public function flushRtIndex($index) |
||
256 | |||
257 | /** |
||
258 | * TRUNCATE RTINDEX syntax |
||
259 | * |
||
260 | * @param string $index |
||
261 | * |
||
262 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
263 | */ |
||
264 | public function truncateRtIndex($index) |
||
268 | |||
269 | /** |
||
270 | * OPTIMIZE INDEX syntax |
||
271 | * |
||
272 | * @param string $index |
||
273 | * |
||
274 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
275 | */ |
||
276 | public function optimizeIndex($index) |
||
280 | |||
281 | /** |
||
282 | * SHOW INDEX STATUS syntax |
||
283 | * |
||
284 | * @param $index |
||
285 | * |
||
286 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
287 | */ |
||
288 | public function showIndexStatus($index) |
||
292 | |||
293 | /** |
||
294 | * FLUSH RAMCHUNK syntax |
||
295 | * |
||
296 | * @param $index |
||
297 | * |
||
298 | * @return SphinxQL A SphinxQL object ready to be ->execute(); |
||
299 | */ |
||
300 | public function flushRamchunk($index) |
||
304 | } |
||
305 |