@@ -33,82 +33,82 @@ discard block |
||
33 | 33 | ///////////////////////////////////////////////////////////////////////////// |
34 | 34 | |
35 | 35 | /// known searchd commands |
36 | -define("SEARCHD_COMMAND_SEARCH", 0); |
|
37 | -define("SEARCHD_COMMAND_EXCERPT", 1); |
|
38 | -define("SEARCHD_COMMAND_UPDATE", 2); |
|
39 | -define("SEARCHD_COMMAND_KEYWORDS", 3); |
|
40 | -define("SEARCHD_COMMAND_PERSIST", 4); |
|
41 | -define("SEARCHD_COMMAND_STATUS", 5); |
|
36 | +define("SEARCHD_COMMAND_SEARCH", 0); |
|
37 | +define("SEARCHD_COMMAND_EXCERPT", 1); |
|
38 | +define("SEARCHD_COMMAND_UPDATE", 2); |
|
39 | +define("SEARCHD_COMMAND_KEYWORDS", 3); |
|
40 | +define("SEARCHD_COMMAND_PERSIST", 4); |
|
41 | +define("SEARCHD_COMMAND_STATUS", 5); |
|
42 | 42 | define("SEARCHD_COMMAND_FLUSHATTRS", 7); |
43 | 43 | |
44 | 44 | /// current client-side command implementation versions |
45 | -define("VER_COMMAND_SEARCH", 0x11E); |
|
46 | -define("VER_COMMAND_EXCERPT", 0x104); |
|
47 | -define("VER_COMMAND_UPDATE", 0x103); |
|
48 | -define("VER_COMMAND_KEYWORDS", 0x100); |
|
49 | -define("VER_COMMAND_STATUS", 0x101); |
|
50 | -define("VER_COMMAND_QUERY", 0x100); |
|
45 | +define("VER_COMMAND_SEARCH", 0x11E); |
|
46 | +define("VER_COMMAND_EXCERPT", 0x104); |
|
47 | +define("VER_COMMAND_UPDATE", 0x103); |
|
48 | +define("VER_COMMAND_KEYWORDS", 0x100); |
|
49 | +define("VER_COMMAND_STATUS", 0x101); |
|
50 | +define("VER_COMMAND_QUERY", 0x100); |
|
51 | 51 | define("VER_COMMAND_FLUSHATTRS", 0x100); |
52 | 52 | |
53 | 53 | /// known searchd status codes |
54 | -define("SEARCHD_OK", 0); |
|
55 | -define("SEARCHD_ERROR", 1); |
|
56 | -define("SEARCHD_RETRY", 2); |
|
54 | +define("SEARCHD_OK", 0); |
|
55 | +define("SEARCHD_ERROR", 1); |
|
56 | +define("SEARCHD_RETRY", 2); |
|
57 | 57 | define("SEARCHD_WARNING", 3); |
58 | 58 | |
59 | 59 | /// known match modes |
60 | -define("SPH_MATCH_ALL", 0); |
|
61 | -define("SPH_MATCH_ANY", 1); |
|
62 | -define("SPH_MATCH_PHRASE", 2); |
|
63 | -define("SPH_MATCH_BOOLEAN", 3); |
|
64 | -define("SPH_MATCH_EXTENDED", 4); |
|
65 | -define("SPH_MATCH_FULLSCAN", 5); |
|
60 | +define("SPH_MATCH_ALL", 0); |
|
61 | +define("SPH_MATCH_ANY", 1); |
|
62 | +define("SPH_MATCH_PHRASE", 2); |
|
63 | +define("SPH_MATCH_BOOLEAN", 3); |
|
64 | +define("SPH_MATCH_EXTENDED", 4); |
|
65 | +define("SPH_MATCH_FULLSCAN", 5); |
|
66 | 66 | define("SPH_MATCH_EXTENDED2", 6); // extended engine V2 (TEMPORARY, WILL BE REMOVED) |
67 | 67 | |
68 | 68 | /// known ranking modes (ext2 only) |
69 | 69 | define("SPH_RANK_PROXIMITY_BM25", 0); ///< default mode, phrase proximity major factor and BM25 minor one |
70 | -define("SPH_RANK_BM25", 1); ///< statistical mode, BM25 ranking only (faster but worse quality) |
|
71 | -define("SPH_RANK_NONE", 2); ///< no ranking, all matches get a weight of 1 |
|
72 | -define("SPH_RANK_WORDCOUNT", 3); ///< simple word-count weighting, rank is a weighted sum of per-field keyword occurence counts |
|
73 | -define("SPH_RANK_PROXIMITY", 4); |
|
74 | -define("SPH_RANK_MATCHANY", 5); |
|
75 | -define("SPH_RANK_FIELDMASK", 6); |
|
76 | -define("SPH_RANK_SPH04", 7); |
|
77 | -define("SPH_RANK_EXPR", 8); |
|
78 | -define("SPH_RANK_TOTAL", 9); |
|
70 | +define("SPH_RANK_BM25", 1); ///< statistical mode, BM25 ranking only (faster but worse quality) |
|
71 | +define("SPH_RANK_NONE", 2); ///< no ranking, all matches get a weight of 1 |
|
72 | +define("SPH_RANK_WORDCOUNT", 3); ///< simple word-count weighting, rank is a weighted sum of per-field keyword occurence counts |
|
73 | +define("SPH_RANK_PROXIMITY", 4); |
|
74 | +define("SPH_RANK_MATCHANY", 5); |
|
75 | +define("SPH_RANK_FIELDMASK", 6); |
|
76 | +define("SPH_RANK_SPH04", 7); |
|
77 | +define("SPH_RANK_EXPR", 8); |
|
78 | +define("SPH_RANK_TOTAL", 9); |
|
79 | 79 | |
80 | 80 | /// known sort modes |
81 | -define("SPH_SORT_RELEVANCE", 0); |
|
82 | -define("SPH_SORT_ATTR_DESC", 1); |
|
83 | -define("SPH_SORT_ATTR_ASC", 2); |
|
81 | +define("SPH_SORT_RELEVANCE", 0); |
|
82 | +define("SPH_SORT_ATTR_DESC", 1); |
|
83 | +define("SPH_SORT_ATTR_ASC", 2); |
|
84 | 84 | define("SPH_SORT_TIME_SEGMENTS", 3); |
85 | -define("SPH_SORT_EXTENDED", 4); |
|
86 | -define("SPH_SORT_EXPR", 5); |
|
85 | +define("SPH_SORT_EXTENDED", 4); |
|
86 | +define("SPH_SORT_EXPR", 5); |
|
87 | 87 | |
88 | 88 | /// known filter types |
89 | -define("SPH_FILTER_VALUES", 0); |
|
90 | -define("SPH_FILTER_RANGE", 1); |
|
89 | +define("SPH_FILTER_VALUES", 0); |
|
90 | +define("SPH_FILTER_RANGE", 1); |
|
91 | 91 | define("SPH_FILTER_FLOATRANGE", 2); |
92 | -define("SPH_FILTER_STRING", 3); |
|
92 | +define("SPH_FILTER_STRING", 3); |
|
93 | 93 | |
94 | 94 | /// known attribute types |
95 | -define("SPH_ATTR_INTEGER", 1); |
|
95 | +define("SPH_ATTR_INTEGER", 1); |
|
96 | 96 | define("SPH_ATTR_TIMESTAMP", 2); |
97 | -define("SPH_ATTR_ORDINAL", 3); |
|
98 | -define("SPH_ATTR_BOOL", 4); |
|
99 | -define("SPH_ATTR_FLOAT", 5); |
|
100 | -define("SPH_ATTR_BIGINT", 6); |
|
101 | -define("SPH_ATTR_STRING", 7); |
|
102 | -define("SPH_ATTR_FACTORS", 1001); |
|
103 | -define("SPH_ATTR_MULTI", 0x40000001); |
|
104 | -define("SPH_ATTR_MULTI64", 0x40000002); |
|
97 | +define("SPH_ATTR_ORDINAL", 3); |
|
98 | +define("SPH_ATTR_BOOL", 4); |
|
99 | +define("SPH_ATTR_FLOAT", 5); |
|
100 | +define("SPH_ATTR_BIGINT", 6); |
|
101 | +define("SPH_ATTR_STRING", 7); |
|
102 | +define("SPH_ATTR_FACTORS", 1001); |
|
103 | +define("SPH_ATTR_MULTI", 0x40000001); |
|
104 | +define("SPH_ATTR_MULTI64", 0x40000002); |
|
105 | 105 | |
106 | 106 | /// known grouping functions |
107 | -define("SPH_GROUPBY_DAY", 0); |
|
108 | -define("SPH_GROUPBY_WEEK", 1); |
|
109 | -define("SPH_GROUPBY_MONTH", 2); |
|
110 | -define("SPH_GROUPBY_YEAR", 3); |
|
111 | -define("SPH_GROUPBY_ATTR", 4); |
|
107 | +define("SPH_GROUPBY_DAY", 0); |
|
108 | +define("SPH_GROUPBY_WEEK", 1); |
|
109 | +define("SPH_GROUPBY_MONTH", 2); |
|
110 | +define("SPH_GROUPBY_YEAR", 3); |
|
111 | +define("SPH_GROUPBY_ATTR", 4); |
|
112 | 112 | define("SPH_GROUPBY_ATTRPAIR", 5); |
113 | 113 | |
114 | 114 | // important properties of PHP's integers: |
@@ -146,17 +146,17 @@ discard block |
||
146 | 146 | if (PHP_INT_SIZE>=8) |
147 | 147 | { |
148 | 148 | $v = (int)$v; |
149 | - return pack("NN", $v>>32, $v&0xFFFFFFFF); |
|
149 | + return pack("NN", $v >> 32, $v & 0xFFFFFFFF); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | // x32, int |
153 | 153 | if (is_int($v)) |
154 | - return pack("NN", $v < 0 ? -1 : 0, $v); |
|
154 | + return pack("NN", $v<0 ? -1 : 0, $v); |
|
155 | 155 | |
156 | 156 | // x32, bcmath |
157 | 157 | if (function_exists("bcmul")) |
158 | 158 | { |
159 | - if (bccomp($v, 0) == -1) |
|
159 | + if (bccomp($v, 0)==-1) |
|
160 | 160 | $v = bcadd("18446744073709551616", $v); |
161 | 161 | $h = bcdiv($v, "4294967296", 0); |
162 | 162 | $l = bcmod($v, "4294967296"); |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | $lo = abs((float)substr($v, $p)); |
169 | 169 | $hi = abs((float)substr($v, 0, $p)); |
170 | 170 | |
171 | - $m = $lo + $hi*1316134912.0; // (10 ^ 13) % (1 << 32) = 1316134912 |
|
172 | - $q = floor($m/4294967296.0); |
|
173 | - $l = $m - ($q*4294967296.0); |
|
174 | - $h = $hi*2328.0 + $q; // (10 ^ 13) / (1 << 32) = 2328 |
|
171 | + $m = $lo + $hi * 1316134912.0; // (10 ^ 13) % (1 << 32) = 1316134912 |
|
172 | + $q = floor($m / 4294967296.0); |
|
173 | + $l = $m - ($q * 4294967296.0); |
|
174 | + $h = $hi * 2328.0 + $q; // (10 ^ 13) / (1 << 32) = 2328 |
|
175 | 175 | |
176 | 176 | if ($v<0) |
177 | 177 | { |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | |
199 | 199 | // x64, int |
200 | 200 | if (is_int($v)) |
201 | - return pack("NN", $v>>32, $v&0xFFFFFFFF); |
|
201 | + return pack("NN", $v >> 32, $v & 0xFFFFFFFF); |
|
202 | 202 | |
203 | 203 | // x64, bcmath |
204 | 204 | if (function_exists("bcmul")) |
@@ -213,9 +213,9 @@ discard block |
||
213 | 213 | $lo = (int)substr($v, $p); |
214 | 214 | $hi = (int)substr($v, 0, $p); |
215 | 215 | |
216 | - $m = $lo + $hi*1316134912; |
|
216 | + $m = $lo + $hi * 1316134912; |
|
217 | 217 | $l = $m % 4294967296; |
218 | - $h = $hi*2328 + (int)($m/4294967296); |
|
218 | + $h = $hi * 2328 + (int)($m / 4294967296); |
|
219 | 219 | |
220 | 220 | return pack("NN", $h, $l); |
221 | 221 | } |
@@ -237,10 +237,10 @@ discard block |
||
237 | 237 | $lo = (float)substr($v, $p); |
238 | 238 | $hi = (float)substr($v, 0, $p); |
239 | 239 | |
240 | - $m = $lo + $hi*1316134912.0; |
|
240 | + $m = $lo + $hi * 1316134912.0; |
|
241 | 241 | $q = floor($m / 4294967296.0); |
242 | 242 | $l = $m - ($q * 4294967296.0); |
243 | - $h = $hi*2328.0 + $q; |
|
243 | + $h = $hi * 2328.0 + $q; |
|
244 | 244 | |
245 | 245 | return pack("NN", $h, $l); |
246 | 246 | } |
@@ -252,12 +252,12 @@ discard block |
||
252 | 252 | |
253 | 253 | if (PHP_INT_SIZE>=8) |
254 | 254 | { |
255 | - if ($hi<0) $hi += (1<<32); // because php 5.2.2 to 5.2.5 is totally fucked up again |
|
256 | - if ($lo<0) $lo += (1<<32); |
|
255 | + if ($hi<0) $hi += (1 << 32); // because php 5.2.2 to 5.2.5 is totally fucked up again |
|
256 | + if ($lo<0) $lo += (1 << 32); |
|
257 | 257 | |
258 | 258 | // x64, int |
259 | 259 | if ($hi<=2147483647) |
260 | - return ($hi<<32) + $lo; |
|
260 | + return ($hi << 32) + $lo; |
|
261 | 261 | |
262 | 262 | // x64, bcmath |
263 | 263 | if (function_exists("bcmul")) |
@@ -297,18 +297,18 @@ discard block |
||
297 | 297 | $hi = (float)$hi; |
298 | 298 | $lo = (float)$lo; |
299 | 299 | |
300 | - $q = floor($hi/10000000.0); |
|
301 | - $r = $hi - $q*10000000.0; |
|
302 | - $m = $lo + $r*4967296.0; |
|
303 | - $mq = floor($m/10000000.0); |
|
304 | - $l = $m - $mq*10000000.0; |
|
305 | - $h = $q*4294967296.0 + $r*429.0 + $mq; |
|
300 | + $q = floor($hi / 10000000.0); |
|
301 | + $r = $hi - $q * 10000000.0; |
|
302 | + $m = $lo + $r * 4967296.0; |
|
303 | + $mq = floor($m / 10000000.0); |
|
304 | + $l = $m - $mq * 10000000.0; |
|
305 | + $h = $q * 4294967296.0 + $r * 429.0 + $mq; |
|
306 | 306 | |
307 | 307 | $h = sprintf("%.0f", $h); |
308 | 308 | $l = sprintf("%07.0f", $l); |
309 | 309 | if ($h=="0") |
310 | - return sprintf( "%.0f", (float)$l); |
|
311 | - return $h . $l; |
|
310 | + return sprintf("%.0f", (float)$l); |
|
311 | + return $h.$l; |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | // unpack 64-bit signed |
@@ -319,10 +319,10 @@ discard block |
||
319 | 319 | // x64 |
320 | 320 | if (PHP_INT_SIZE>=8) |
321 | 321 | { |
322 | - if ($hi<0) $hi += (1<<32); // because php 5.2.2 to 5.2.5 is totally fucked up again |
|
323 | - if ($lo<0) $lo += (1<<32); |
|
322 | + if ($hi<0) $hi += (1 << 32); // because php 5.2.2 to 5.2.5 is totally fucked up again |
|
323 | + if ($lo<0) $lo += (1 << 32); |
|
324 | 324 | |
325 | - return ($hi<<32) + $lo; |
|
325 | + return ($hi << 32) + $lo; |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | // x32, int |
@@ -355,18 +355,18 @@ discard block |
||
355 | 355 | |
356 | 356 | // x32, bcmath |
357 | 357 | if (function_exists("bcmul")) |
358 | - return $neg . bcadd(bcadd($lo, bcmul($hi, "4294967296")), $c); |
|
358 | + return $neg.bcadd(bcadd($lo, bcmul($hi, "4294967296")), $c); |
|
359 | 359 | |
360 | 360 | // x32, no-bcmath |
361 | 361 | $hi = (float)$hi; |
362 | 362 | $lo = (float)$lo; |
363 | 363 | |
364 | - $q = floor($hi/10000000.0); |
|
365 | - $r = $hi - $q*10000000.0; |
|
366 | - $m = $lo + $r*4967296.0; |
|
367 | - $mq = floor($m/10000000.0); |
|
368 | - $l = $m - $mq*10000000.0 + $c; |
|
369 | - $h = $q*4294967296.0 + $r*429.0 + $mq; |
|
364 | + $q = floor($hi / 10000000.0); |
|
365 | + $r = $hi - $q * 10000000.0; |
|
366 | + $m = $lo + $r * 4967296.0; |
|
367 | + $mq = floor($m / 10000000.0); |
|
368 | + $l = $m - $mq * 10000000.0 + $c; |
|
369 | + $h = $q * 4294967296.0 + $r * 429.0 + $mq; |
|
370 | 370 | if ($l==10000000) |
371 | 371 | { |
372 | 372 | $l = 0; |
@@ -376,8 +376,8 @@ discard block |
||
376 | 376 | $h = sprintf("%.0f", $h); |
377 | 377 | $l = sprintf("%07.0f", $l); |
378 | 378 | if ($h=="0") |
379 | - return $neg . sprintf( "%.0f", (float)$l); |
|
380 | - return $neg . $h . $l; |
|
379 | + return $neg.sprintf("%.0f", (float)$l); |
|
380 | + return $neg.$h.$l; |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | if (PHP_INT_SIZE>=8) |
387 | 387 | { |
388 | 388 | // x64 route, workaround broken unpack() in 5.2.2+ |
389 | - if ($value<0) $value += (1<<32); |
|
389 | + if ($value<0) $value += (1 << 32); |
|
390 | 390 | return $value; |
391 | 391 | } |
392 | 392 | else |
@@ -400,10 +400,10 @@ discard block |
||
400 | 400 | { |
401 | 401 | if ($on) |
402 | 402 | { |
403 | - $flag |=(1<<$bit); |
|
403 | + $flag |= (1 << $bit); |
|
404 | 404 | } else |
405 | 405 | { |
406 | - $reset = 16777215 ^(1<<$bit); |
|
406 | + $reset = 16777215 ^ (1 << $bit); |
|
407 | 407 | $flag = $flag & $reset; |
408 | 408 | } |
409 | 409 | return $flag; |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | ///////////////////////////////////////////////////////////////////////////// |
462 | 462 | |
463 | 463 | /// create a new client object and fill defaults |
464 | - function SphinxClient () |
|
464 | + function SphinxClient() |
|
465 | 465 | { |
466 | 466 | // per-client-object settings |
467 | 467 | $this->_host = "localhost"; |
@@ -473,12 +473,12 @@ discard block |
||
473 | 473 | $this->_offset = 0; |
474 | 474 | $this->_limit = 20; |
475 | 475 | $this->_mode = SPH_MATCH_EXTENDED2; |
476 | - $this->_weights = array (); |
|
476 | + $this->_weights = array(); |
|
477 | 477 | $this->_sort = SPH_SORT_RELEVANCE; |
478 | 478 | $this->_sortby = ""; |
479 | 479 | $this->_min_id = 0; |
480 | 480 | $this->_max_id = 0; |
481 | - $this->_filters = array (); |
|
481 | + $this->_filters = array(); |
|
482 | 482 | $this->_groupby = ""; |
483 | 483 | $this->_groupfunc = SPH_GROUPBY_DAY; |
484 | 484 | $this->_groupsort = "@group desc"; |
@@ -487,8 +487,8 @@ discard block |
||
487 | 487 | $this->_cutoff = 0; |
488 | 488 | $this->_retrycount = 0; |
489 | 489 | $this->_retrydelay = 0; |
490 | - $this->_anchor = array (); |
|
491 | - $this->_indexweights = array (); |
|
490 | + $this->_anchor = array(); |
|
491 | + $this->_indexweights = array(); |
|
492 | 492 | $this->_ranker = SPH_RANK_PROXIMITY_BM25; |
493 | 493 | $this->_rankexpr = ""; |
494 | 494 | $this->_maxquerytime = 0; |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | $this->_warning = ""; |
507 | 507 | $this->_connerror = false; |
508 | 508 | |
509 | - $this->_reqs = array ();// requests storage (for multi-query case) |
|
509 | + $this->_reqs = array(); // requests storage (for multi-query case) |
|
510 | 510 | $this->_mbenc = ""; |
511 | 511 | $this->_arrayresult = false; |
512 | 512 | $this->_timeout = 0; |
@@ -514,18 +514,18 @@ discard block |
||
514 | 514 | |
515 | 515 | function __destruct() |
516 | 516 | { |
517 | - if ($this->_socket !== false) |
|
517 | + if ($this->_socket!==false) |
|
518 | 518 | fclose($this->_socket); |
519 | 519 | } |
520 | 520 | |
521 | 521 | /// get last error message (string) |
522 | - function GetLastError () |
|
522 | + function GetLastError() |
|
523 | 523 | { |
524 | 524 | return $this->_error; |
525 | 525 | } |
526 | 526 | |
527 | 527 | /// get last warning message (string) |
528 | - function GetLastWarning () |
|
528 | + function GetLastWarning() |
|
529 | 529 | { |
530 | 530 | return $this->_warning; |
531 | 531 | } |
@@ -540,9 +540,9 @@ discard block |
||
540 | 540 | function SetServer($host, $port = 0) |
541 | 541 | { |
542 | 542 | assert(is_string($host)); |
543 | - if ($host[0] == '/') |
|
543 | + if ($host[0]=='/') |
|
544 | 544 | { |
545 | - $this->_path = 'unix://' . $host; |
|
545 | + $this->_path = 'unix://'.$host; |
|
546 | 546 | return; |
547 | 547 | } |
548 | 548 | if (substr($host, 0, 7)=="unix://") |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | $this->_host = $host; |
555 | 555 | $port = intval($port); |
556 | 556 | assert(0<=$port && $port<65536); |
557 | - $this->_port =($port==0) ? 9312 : $port; |
|
557 | + $this->_port = ($port==0) ? 9312 : $port; |
|
558 | 558 | $this->_path = ''; |
559 | 559 | } |
560 | 560 | |
@@ -568,7 +568,7 @@ discard block |
||
568 | 568 | |
569 | 569 | function _Send($handle, $data, $length) |
570 | 570 | { |
571 | - if (feof($handle) || fwrite($handle, $data, $length) !== $length) |
|
571 | + if (feof($handle) || fwrite($handle, $data, $length)!==$length) |
|
572 | 572 | { |
573 | 573 | $this->_error = 'connection unexpectedly closed (timed out?)'; |
574 | 574 | $this->_connerror = true; |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | ///////////////////////////////////////////////////////////////////////////// |
581 | 581 | |
582 | 582 | /// enter mbstring workaround mode |
583 | - function _MBPush () |
|
583 | + function _MBPush() |
|
584 | 584 | { |
585 | 585 | $this->_mbenc = ""; |
586 | 586 | if (ini_get("mbstring.func_overload") & 2) |
@@ -591,14 +591,14 @@ discard block |
||
591 | 591 | } |
592 | 592 | |
593 | 593 | /// leave mbstring workaround mode |
594 | - function _MBPop () |
|
594 | + function _MBPop() |
|
595 | 595 | { |
596 | 596 | if ($this->_mbenc) |
597 | 597 | mb_internal_encoding($this->_mbenc); |
598 | 598 | } |
599 | 599 | |
600 | 600 | /// connect to searchd server |
601 | - function _Connect () |
|
601 | + function _Connect() |
|
602 | 602 | { |
603 | 603 | if ($this->_socket!==false) |
604 | 604 | { |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | } |
690 | 690 | } |
691 | 691 | } |
692 | - if ($this->_socket === false) |
|
692 | + if ($this->_socket===false) |
|
693 | 693 | fclose($fp); |
694 | 694 | |
695 | 695 | // check response |
@@ -707,16 +707,16 @@ discard block |
||
707 | 707 | { |
708 | 708 | list(,$wlen) = unpack("N*", substr($response, 0, 4)); |
709 | 709 | $this->_warning = substr($response, 4, $wlen); |
710 | - return substr($response, 4+$wlen); |
|
710 | + return substr($response, 4 + $wlen); |
|
711 | 711 | } |
712 | 712 | if ($status==SEARCHD_ERROR) |
713 | 713 | { |
714 | - $this->_error = "searchd error: " . substr($response, 4); |
|
714 | + $this->_error = "searchd error: ".substr($response, 4); |
|
715 | 715 | return false; |
716 | 716 | } |
717 | 717 | if ($status==SEARCHD_RETRY) |
718 | 718 | { |
719 | - $this->_error = "temporary searchd error: " . substr($response, 4); |
|
719 | + $this->_error = "temporary searchd error: ".substr($response, 4); |
|
720 | 720 | return false; |
721 | 721 | } |
722 | 722 | if ($status!=SEARCHD_OK) |
@@ -729,7 +729,7 @@ discard block |
||
729 | 729 | if ($ver<$client_ver) |
730 | 730 | { |
731 | 731 | $this->_warning = sprintf("searchd command v.%d.%d older than client's v.%d.%d, some options might not work", |
732 | - $ver>>8, $ver&0xff, $client_ver>>8, $client_ver&0xff); |
|
732 | + $ver >> 8, $ver & 0xff, $client_ver >> 8, $client_ver & 0xff); |
|
733 | 733 | } |
734 | 734 | |
735 | 735 | return $response; |
@@ -741,7 +741,7 @@ discard block |
||
741 | 741 | |
742 | 742 | /// set offset and count into result set, |
743 | 743 | /// and optionally set max-matches and cutoff limits |
744 | - function SetLimits($offset, $limit, $max=0, $cutoff=0) |
|
744 | + function SetLimits($offset, $limit, $max = 0, $cutoff = 0) |
|
745 | 745 | { |
746 | 746 | assert(is_int($offset)); |
747 | 747 | assert(is_int($limit)); |
@@ -780,7 +780,7 @@ discard block |
||
780 | 780 | } |
781 | 781 | |
782 | 782 | /// set ranking mode |
783 | - function SetRankingMode($ranker, $rankexpr="") |
|
783 | + function SetRankingMode($ranker, $rankexpr = "") |
|
784 | 784 | { |
785 | 785 | assert($ranker===0 || $ranker>=1 && $ranker<SPH_RANK_TOTAL); |
786 | 786 | assert(is_string($rankexpr)); |
@@ -789,9 +789,9 @@ discard block |
||
789 | 789 | } |
790 | 790 | |
791 | 791 | /// set matches sorting mode |
792 | - function SetSortMode($mode, $sortby="") |
|
792 | + function SetSortMode($mode, $sortby = "") |
|
793 | 793 | { |
794 | - assert ( |
|
794 | + assert( |
|
795 | 795 | $mode==SPH_SORT_RELEVANCE || |
796 | 796 | $mode==SPH_SORT_ATTR_DESC || |
797 | 797 | $mode==SPH_SORT_ATTR_ASC || |
@@ -849,7 +849,7 @@ discard block |
||
849 | 849 | |
850 | 850 | /// set values set filter |
851 | 851 | /// only match records where $attribute value is in given set |
852 | - function SetFilter($attribute, $values, $exclude=false) |
|
852 | + function SetFilter($attribute, $values, $exclude = false) |
|
853 | 853 | { |
854 | 854 | assert(is_string($attribute)); |
855 | 855 | assert(is_array($values)); |
@@ -866,7 +866,7 @@ discard block |
||
866 | 866 | |
867 | 867 | /// set string filter |
868 | 868 | /// only match records where $attribute value is equal |
869 | - function SetFilterString($attribute, $value, $exclude=false) |
|
869 | + function SetFilterString($attribute, $value, $exclude = false) |
|
870 | 870 | { |
871 | 871 | assert(is_string($attribute)); |
872 | 872 | assert(is_string($value)); |
@@ -875,7 +875,7 @@ discard block |
||
875 | 875 | |
876 | 876 | /// set range filter |
877 | 877 | /// only match records if $attribute value is beetwen $min and $max (inclusive) |
878 | - function SetFilterRange($attribute, $min, $max, $exclude=false) |
|
878 | + function SetFilterRange($attribute, $min, $max, $exclude = false) |
|
879 | 879 | { |
880 | 880 | assert(is_string($attribute)); |
881 | 881 | assert(is_numeric($min)); |
@@ -887,7 +887,7 @@ discard block |
||
887 | 887 | |
888 | 888 | /// set float range filter |
889 | 889 | /// only match records if $attribute value is beetwen $min and $max (inclusive) |
890 | - function SetFilterFloatRange($attribute, $min, $max, $exclude=false) |
|
890 | + function SetFilterFloatRange($attribute, $min, $max, $exclude = false) |
|
891 | 891 | { |
892 | 892 | assert(is_string($attribute)); |
893 | 893 | assert(is_float($min)); |
@@ -911,7 +911,7 @@ discard block |
||
911 | 911 | } |
912 | 912 | |
913 | 913 | /// set grouping attribute and function |
914 | - function SetGroupBy($attribute, $func, $groupsort="@group desc") |
|
914 | + function SetGroupBy($attribute, $func, $groupsort = "@group desc") |
|
915 | 915 | { |
916 | 916 | assert(is_string($attribute)); |
917 | 917 | assert(is_string($groupsort)); |
@@ -935,7 +935,7 @@ discard block |
||
935 | 935 | } |
936 | 936 | |
937 | 937 | /// set distributed retries count and delay |
938 | - function SetRetries($count, $delay=0) |
|
938 | + function SetRetries($count, $delay = 0) |
|
939 | 939 | { |
940 | 940 | assert(is_int($count) && $count>=0); |
941 | 941 | assert(is_int($delay) && $delay>=0); |
@@ -974,18 +974,18 @@ discard block |
||
974 | 974 | function SetQueryFlag($flag_name, $flag_value) |
975 | 975 | { |
976 | 976 | $known_names = array("reverse_scan", "sort_method", "max_predicted_time", "boolean_simplify", "idf", "global_idf", "low_priority"); |
977 | - $flags = array ( |
|
977 | + $flags = array( |
|
978 | 978 | "reverse_scan" => array(0, 1), |
979 | 979 | "sort_method" => array("pq", "kbuffer"), |
980 | 980 | "max_predicted_time" => array(0), |
981 | 981 | "boolean_simplify" => array(true, false), |
982 | - "idf" => array ("normalized", "plain", "tfidf_normalized", "tfidf_unnormalized"), |
|
982 | + "idf" => array("normalized", "plain", "tfidf_normalized", "tfidf_unnormalized"), |
|
983 | 983 | "global_idf" => array(true, false), |
984 | 984 | "low_priority" => array(true, false) |
985 | 985 | ); |
986 | 986 | |
987 | 987 | assert(isset($flag_name, $known_names)); |
988 | - assert(in_array( $flag_value, $flags[$flag_name], true) ||($flag_name=="max_predicted_time" && is_int($flag_value) && $flag_value>=0)); |
|
988 | + assert(in_array($flag_value, $flags[$flag_name], true) || ($flag_name=="max_predicted_time" && is_int($flag_value) && $flag_value>=0)); |
|
989 | 989 | |
990 | 990 | if ($flag_name=="reverse_scan") $this->_query_flags = sphSetBit($this->_query_flags, 0, $flag_value==1); |
991 | 991 | if ($flag_name=="sort_method") $this->_query_flags = sphSetBit($this->_query_flags, 1, $flag_value=="kbuffer"); |
@@ -995,9 +995,9 @@ discard block |
||
995 | 995 | $this->_predictedtime = (int)$flag_value; |
996 | 996 | } |
997 | 997 | if ($flag_name=="boolean_simplify") $this->_query_flags = sphSetBit($this->_query_flags, 3, $flag_value); |
998 | - if ($flag_name=="idf" &&($flag_value=="normalized" || $flag_value=="plain")) $this->_query_flags = sphSetBit($this->_query_flags, 4, $flag_value=="plain"); |
|
998 | + if ($flag_name=="idf" && ($flag_value=="normalized" || $flag_value=="plain")) $this->_query_flags = sphSetBit($this->_query_flags, 4, $flag_value=="plain"); |
|
999 | 999 | if ($flag_name=="global_idf") $this->_query_flags = sphSetBit($this->_query_flags, 5, $flag_value); |
1000 | - if ($flag_name=="idf" &&($flag_value=="tfidf_normalized" || $flag_value=="tfidf_unnormalized")) $this->_query_flags = sphSetBit($this->_query_flags, 6, $flag_value=="tfidf_normalized"); |
|
1000 | + if ($flag_name=="idf" && ($flag_value=="tfidf_normalized" || $flag_value=="tfidf_unnormalized")) $this->_query_flags = sphSetBit($this->_query_flags, 6, $flag_value=="tfidf_normalized"); |
|
1001 | 1001 | if ($flag_name=="low_priority") $this->_query_flags = sphSetBit($this->_query_flags, 8, $flag_value); |
1002 | 1002 | } |
1003 | 1003 | |
@@ -1020,14 +1020,14 @@ discard block |
||
1020 | 1020 | ////////////////////////////////////////////////////////////////////////////// |
1021 | 1021 | |
1022 | 1022 | /// clear all filters (for multi-queries) |
1023 | - function ResetFilters () |
|
1023 | + function ResetFilters() |
|
1024 | 1024 | { |
1025 | 1025 | $this->_filters = array(); |
1026 | 1026 | $this->_anchor = array(); |
1027 | 1027 | } |
1028 | 1028 | |
1029 | 1029 | /// clear groupby settings (for multi-queries) |
1030 | - function ResetGroupBy () |
|
1030 | + function ResetGroupBy() |
|
1031 | 1031 | { |
1032 | 1032 | $this->_groupby = ""; |
1033 | 1033 | $this->_groupfunc = SPH_GROUPBY_DAY; |
@@ -1036,18 +1036,18 @@ discard block |
||
1036 | 1036 | } |
1037 | 1037 | |
1038 | 1038 | /// clear all attribute value overrides (for multi-queries) |
1039 | - function ResetOverrides () |
|
1039 | + function ResetOverrides() |
|
1040 | 1040 | { |
1041 | - $this->_overrides = array (); |
|
1041 | + $this->_overrides = array(); |
|
1042 | 1042 | } |
1043 | 1043 | |
1044 | - function ResetQueryFlag () |
|
1044 | + function ResetQueryFlag() |
|
1045 | 1045 | { |
1046 | 1046 | $this->_query_flags = sphSetBit(0, 6, true); // default idf=tfidf_normalized |
1047 | 1047 | $this->_predictedtime = 0; |
1048 | 1048 | } |
1049 | 1049 | |
1050 | - function ResetOuterSelect () |
|
1050 | + function ResetOuterSelect() |
|
1051 | 1051 | { |
1052 | 1052 | $this->_outerorderby = ''; |
1053 | 1053 | $this->_outeroffset = 0; |
@@ -1059,13 +1059,13 @@ discard block |
||
1059 | 1059 | |
1060 | 1060 | /// connect to searchd server, run given search query through given indexes, |
1061 | 1061 | /// and return the search results |
1062 | - function Query($query, $index="*", $comment="") |
|
1062 | + function Query($query, $index = "*", $comment = "") |
|
1063 | 1063 | { |
1064 | 1064 | assert(empty($this->_reqs)); |
1065 | 1065 | |
1066 | 1066 | $this->AddQuery($query, $index, $comment); |
1067 | - $results = $this->RunQueries (); |
|
1068 | - $this->_reqs = array (); // just in case it failed too early |
|
1067 | + $results = $this->RunQueries(); |
|
1068 | + $this->_reqs = array(); // just in case it failed too early |
|
1069 | 1069 | |
1070 | 1070 | if (!is_array($results)) |
1071 | 1071 | return false; // probably network error; error message should be already filled |
@@ -1088,30 +1088,30 @@ discard block |
||
1088 | 1088 | |
1089 | 1089 | /// add query to multi-query batch |
1090 | 1090 | /// returns index into results array from RunQueries() call |
1091 | - function AddQuery($query, $index="*", $comment="") |
|
1091 | + function AddQuery($query, $index = "*", $comment = "") |
|
1092 | 1092 | { |
1093 | 1093 | // mbstring workaround |
1094 | - $this->_MBPush (); |
|
1094 | + $this->_MBPush(); |
|
1095 | 1095 | |
1096 | 1096 | // build request |
1097 | 1097 | $req = pack("NNNNN", $this->_query_flags, $this->_offset, $this->_limit, $this->_mode, $this->_ranker); |
1098 | 1098 | if ($this->_ranker==SPH_RANK_EXPR) |
1099 | - $req .= pack("N", strlen($this->_rankexpr)) . $this->_rankexpr; |
|
1099 | + $req .= pack("N", strlen($this->_rankexpr)).$this->_rankexpr; |
|
1100 | 1100 | $req .= pack("N", $this->_sort); // (deprecated) sort mode |
1101 | - $req .= pack("N", strlen($this->_sortby)) . $this->_sortby; |
|
1102 | - $req .= pack("N", strlen($query)) . $query; // query itself |
|
1101 | + $req .= pack("N", strlen($this->_sortby)).$this->_sortby; |
|
1102 | + $req .= pack("N", strlen($query)).$query; // query itself |
|
1103 | 1103 | $req .= pack("N", count($this->_weights)); // weights |
1104 | 1104 | foreach ($this->_weights as $weight) |
1105 | 1105 | $req .= pack("N", (int)$weight); |
1106 | - $req .= pack("N", strlen($index)) . $index; // indexes |
|
1106 | + $req .= pack("N", strlen($index)).$index; // indexes |
|
1107 | 1107 | $req .= pack("N", 1); // id64 range marker |
1108 | - $req .= sphPackU64($this->_min_id) . sphPackU64($this->_max_id); // id64 range |
|
1108 | + $req .= sphPackU64($this->_min_id).sphPackU64($this->_max_id); // id64 range |
|
1109 | 1109 | |
1110 | 1110 | // filters |
1111 | 1111 | $req .= pack("N", count($this->_filters)); |
1112 | 1112 | foreach ($this->_filters as $filter) |
1113 | 1113 | { |
1114 | - $req .= pack("N", strlen($filter["attr"])) . $filter["attr"]; |
|
1114 | + $req .= pack("N", strlen($filter["attr"])).$filter["attr"]; |
|
1115 | 1115 | $req .= pack("N", $filter["type"]); |
1116 | 1116 | switch ($filter["type"]) |
1117 | 1117 | { |
@@ -1122,15 +1122,15 @@ discard block |
||
1122 | 1122 | break; |
1123 | 1123 | |
1124 | 1124 | case SPH_FILTER_RANGE: |
1125 | - $req .= sphPackI64($filter["min"]) . sphPackI64($filter["max"]); |
|
1125 | + $req .= sphPackI64($filter["min"]).sphPackI64($filter["max"]); |
|
1126 | 1126 | break; |
1127 | 1127 | |
1128 | 1128 | case SPH_FILTER_FLOATRANGE: |
1129 | - $req .= $this->_PackFloat($filter["min"]) . $this->_PackFloat($filter["max"]); |
|
1129 | + $req .= $this->_PackFloat($filter["min"]).$this->_PackFloat($filter["max"]); |
|
1130 | 1130 | break; |
1131 | 1131 | |
1132 | 1132 | case SPH_FILTER_STRING: |
1133 | - $req .= pack("N", strlen($filter["value"])) . $filter["value"]; |
|
1133 | + $req .= pack("N", strlen($filter["value"])).$filter["value"]; |
|
1134 | 1134 | break; |
1135 | 1135 | |
1136 | 1136 | default: |
@@ -1140,11 +1140,11 @@ discard block |
||
1140 | 1140 | } |
1141 | 1141 | |
1142 | 1142 | // group-by clause, max-matches count, group-sort clause, cutoff count |
1143 | - $req .= pack("NN", $this->_groupfunc, strlen($this->_groupby)) . $this->_groupby; |
|
1143 | + $req .= pack("NN", $this->_groupfunc, strlen($this->_groupby)).$this->_groupby; |
|
1144 | 1144 | $req .= pack("N", $this->_maxmatches); |
1145 | - $req .= pack("N", strlen($this->_groupsort)) . $this->_groupsort; |
|
1145 | + $req .= pack("N", strlen($this->_groupsort)).$this->_groupsort; |
|
1146 | 1146 | $req .= pack("NNN", $this->_cutoff, $this->_retrycount, $this->_retrydelay); |
1147 | - $req .= pack("N", strlen($this->_groupdistinct)) . $this->_groupdistinct; |
|
1147 | + $req .= pack("N", strlen($this->_groupdistinct)).$this->_groupdistinct; |
|
1148 | 1148 | |
1149 | 1149 | // anchor point |
1150 | 1150 | if (empty($this->_anchor)) |
@@ -1152,17 +1152,17 @@ discard block |
||
1152 | 1152 | $req .= pack("N", 0); |
1153 | 1153 | } else |
1154 | 1154 | { |
1155 | - $a =& $this->_anchor; |
|
1155 | + $a = & $this->_anchor; |
|
1156 | 1156 | $req .= pack("N", 1); |
1157 | - $req .= pack("N", strlen($a["attrlat"])) . $a["attrlat"]; |
|
1158 | - $req .= pack("N", strlen($a["attrlong"])) . $a["attrlong"]; |
|
1159 | - $req .= $this->_PackFloat($a["lat"]) . $this->_PackFloat($a["long"]); |
|
1157 | + $req .= pack("N", strlen($a["attrlat"])).$a["attrlat"]; |
|
1158 | + $req .= pack("N", strlen($a["attrlong"])).$a["attrlong"]; |
|
1159 | + $req .= $this->_PackFloat($a["lat"]).$this->_PackFloat($a["long"]); |
|
1160 | 1160 | } |
1161 | 1161 | |
1162 | 1162 | // per-index weights |
1163 | 1163 | $req .= pack("N", count($this->_indexweights)); |
1164 | 1164 | foreach ($this->_indexweights as $idx=>$weight) |
1165 | - $req .= pack("N", strlen($idx)) . $idx . pack("N", $weight); |
|
1165 | + $req .= pack("N", strlen($idx)).$idx.pack("N", $weight); |
|
1166 | 1166 | |
1167 | 1167 | // max query time |
1168 | 1168 | $req .= pack("N", $this->_maxquerytime); |
@@ -1170,16 +1170,16 @@ discard block |
||
1170 | 1170 | // per-field weights |
1171 | 1171 | $req .= pack("N", count($this->_fieldweights)); |
1172 | 1172 | foreach ($this->_fieldweights as $field=>$weight) |
1173 | - $req .= pack("N", strlen($field)) . $field . pack("N", $weight); |
|
1173 | + $req .= pack("N", strlen($field)).$field.pack("N", $weight); |
|
1174 | 1174 | |
1175 | 1175 | // comment |
1176 | - $req .= pack("N", strlen($comment)) . $comment; |
|
1176 | + $req .= pack("N", strlen($comment)).$comment; |
|
1177 | 1177 | |
1178 | 1178 | // attribute overrides |
1179 | 1179 | $req .= pack("N", count($this->_overrides)); |
1180 | 1180 | foreach ($this->_overrides as $key => $entry) |
1181 | 1181 | { |
1182 | - $req .= pack("N", strlen($entry["attr"])) . $entry["attr"]; |
|
1182 | + $req .= pack("N", strlen($entry["attr"])).$entry["attr"]; |
|
1183 | 1183 | $req .= pack("NN", $entry["type"], count($entry["values"])); |
1184 | 1184 | foreach ($entry["values"] as $id=>$val) |
1185 | 1185 | { |
@@ -1197,13 +1197,13 @@ discard block |
||
1197 | 1197 | } |
1198 | 1198 | |
1199 | 1199 | // select-list |
1200 | - $req .= pack("N", strlen($this->_select)) . $this->_select; |
|
1200 | + $req .= pack("N", strlen($this->_select)).$this->_select; |
|
1201 | 1201 | |
1202 | 1202 | // max_predicted_time |
1203 | 1203 | if ($this->_predictedtime>0) |
1204 | 1204 | $req .= pack("N", (int)$this->_predictedtime); |
1205 | 1205 | |
1206 | - $req .= pack("N", strlen($this->_outerorderby)) . $this->_outerorderby; |
|
1206 | + $req .= pack("N", strlen($this->_outerorderby)).$this->_outerorderby; |
|
1207 | 1207 | $req .= pack("NN", $this->_outeroffset, $this->_outerlimit); |
1208 | 1208 | if ($this->_hasouter) |
1209 | 1209 | $req .= pack("N", 1); |
@@ -1211,15 +1211,15 @@ discard block |
||
1211 | 1211 | $req .= pack("N", 0); |
1212 | 1212 | |
1213 | 1213 | // mbstring workaround |
1214 | - $this->_MBPop (); |
|
1214 | + $this->_MBPop(); |
|
1215 | 1215 | |
1216 | 1216 | // store request to requests array |
1217 | 1217 | $this->_reqs[] = $req; |
1218 | - return count($this->_reqs)-1; |
|
1218 | + return count($this->_reqs) - 1; |
|
1219 | 1219 | } |
1220 | 1220 | |
1221 | 1221 | /// connect to searchd, run queries batch, and return an array of result sets |
1222 | - function RunQueries () |
|
1222 | + function RunQueries() |
|
1223 | 1223 | { |
1224 | 1224 | if (empty($this->_reqs)) |
1225 | 1225 | { |
@@ -1228,29 +1228,29 @@ discard block |
||
1228 | 1228 | } |
1229 | 1229 | |
1230 | 1230 | // mbstring workaround |
1231 | - $this->_MBPush (); |
|
1231 | + $this->_MBPush(); |
|
1232 | 1232 | |
1233 | - if (!( $fp = $this->_Connect())) |
|
1233 | + if (!($fp = $this->_Connect())) |
|
1234 | 1234 | { |
1235 | - $this->_MBPop (); |
|
1235 | + $this->_MBPop(); |
|
1236 | 1236 | return false; |
1237 | 1237 | } |
1238 | 1238 | |
1239 | 1239 | // send query, get response |
1240 | 1240 | $nreqs = count($this->_reqs); |
1241 | 1241 | $req = join("", $this->_reqs); |
1242 | - $len = 8+strlen($req); |
|
1243 | - $req = pack("nnNNN", SEARCHD_COMMAND_SEARCH, VER_COMMAND_SEARCH, $len, 0, $nreqs) . $req; // add header |
|
1242 | + $len = 8 + strlen($req); |
|
1243 | + $req = pack("nnNNN", SEARCHD_COMMAND_SEARCH, VER_COMMAND_SEARCH, $len, 0, $nreqs).$req; // add header |
|
1244 | 1244 | |
1245 | - if (!( $this->_Send($fp, $req, $len+8)) || |
|
1246 | - !( $response = $this->_GetResponse($fp, VER_COMMAND_SEARCH))) |
|
1245 | + if (!($this->_Send($fp, $req, $len + 8)) || |
|
1246 | + !($response = $this->_GetResponse($fp, VER_COMMAND_SEARCH))) |
|
1247 | 1247 | { |
1248 | - $this->_MBPop (); |
|
1248 | + $this->_MBPop(); |
|
1249 | 1249 | return false; |
1250 | 1250 | } |
1251 | 1251 | |
1252 | 1252 | // query sent ok; we can reset reqs now |
1253 | - $this->_reqs = array (); |
|
1253 | + $this->_reqs = array(); |
|
1254 | 1254 | |
1255 | 1255 | // parse and return response |
1256 | 1256 | return $this->_ParseSearchResponse($response, $nreqs); |
@@ -1262,11 +1262,11 @@ discard block |
||
1262 | 1262 | $p = 0; // current position |
1263 | 1263 | $max = strlen($response); // max position for checks, to protect against broken responses |
1264 | 1264 | |
1265 | - $results = array (); |
|
1266 | - for($ires=0; $ires<$nreqs && $p<$max; $ires++) |
|
1265 | + $results = array(); |
|
1266 | + for ($ires = 0; $ires<$nreqs && $p<$max; $ires++) |
|
1267 | 1267 | { |
1268 | 1268 | $results[] = array(); |
1269 | - $result =& $results[$ires]; |
|
1269 | + $result = & $results[$ires]; |
|
1270 | 1270 | |
1271 | 1271 | $result["error"] = ""; |
1272 | 1272 | $result["warning"] = ""; |
@@ -1290,8 +1290,8 @@ discard block |
||
1290 | 1290 | } |
1291 | 1291 | |
1292 | 1292 | // read schema |
1293 | - $fields = array (); |
|
1294 | - $attrs = array (); |
|
1293 | + $fields = array(); |
|
1294 | + $attrs = array(); |
|
1295 | 1295 | |
1296 | 1296 | list(,$nfields) = unpack("N*", substr($response, $p, 4)); $p += 4; |
1297 | 1297 | while ($nfields-->0 && $p<$max) |
@@ -1302,7 +1302,7 @@ discard block |
||
1302 | 1302 | $result["fields"] = $fields; |
1303 | 1303 | |
1304 | 1304 | list(,$nattrs) = unpack("N*", substr($response, $p, 4)); $p += 4; |
1305 | - while ($nattrs-->0 && $p<$max ) |
|
1305 | + while ($nattrs-->0 && $p<$max) |
|
1306 | 1306 | { |
1307 | 1307 | list(,$len) = unpack("N*", substr($response, $p, 4)); $p += 4; |
1308 | 1308 | $attr = substr($response, $p, $len); $p += $len; |
@@ -1344,7 +1344,7 @@ discard block |
||
1344 | 1344 | $result["matches"][$doc]["weight"] = $weight; |
1345 | 1345 | |
1346 | 1346 | // parse and create attributes |
1347 | - $attrvals = array (); |
|
1347 | + $attrvals = array(); |
|
1348 | 1348 | foreach ($attrs as $attr=>$type) |
1349 | 1349 | { |
1350 | 1350 | // handle 64bit ints |
@@ -1367,7 +1367,7 @@ discard block |
||
1367 | 1367 | list(,$val) = unpack("N*", substr($response, $p, 4)); $p += 4; |
1368 | 1368 | if ($type==SPH_ATTR_MULTI) |
1369 | 1369 | { |
1370 | - $attrvals[$attr] = array (); |
|
1370 | + $attrvals[$attr] = array(); |
|
1371 | 1371 | $nvalues = $val; |
1372 | 1372 | while ($nvalues-->0 && $p<$max) |
1373 | 1373 | { |
@@ -1376,7 +1376,7 @@ discard block |
||
1376 | 1376 | } |
1377 | 1377 | } else if ($type==SPH_ATTR_MULTI64) |
1378 | 1378 | { |
1379 | - $attrvals[$attr] = array (); |
|
1379 | + $attrvals[$attr] = array(); |
|
1380 | 1380 | $nvalues = $val; |
1381 | 1381 | while ($nvalues>0 && $p<$max) |
1382 | 1382 | { |
@@ -1389,8 +1389,8 @@ discard block |
||
1389 | 1389 | $p += $val; |
1390 | 1390 | } else if ($type==SPH_ATTR_FACTORS) |
1391 | 1391 | { |
1392 | - $attrvals[$attr] = substr($response, $p, $val-4); |
|
1393 | - $p += $val-4; |
|
1392 | + $attrvals[$attr] = substr($response, $p, $val - 4); |
|
1393 | + $p += $val - 4; |
|
1394 | 1394 | } else |
1395 | 1395 | { |
1396 | 1396 | $attrvals[$attr] = sphFixUint($val); |
@@ -1407,7 +1407,7 @@ discard block |
||
1407 | 1407 | array_values(unpack("N*N*N*N*", substr($response, $p, 16))); |
1408 | 1408 | $result["total"] = sprintf("%u", $total); |
1409 | 1409 | $result["total_found"] = sprintf("%u", $total_found); |
1410 | - $result["time"] = sprintf("%.3f", $msecs/1000); |
|
1410 | + $result["time"] = sprintf("%.3f", $msecs / 1000); |
|
1411 | 1411 | $p += 16; |
1412 | 1412 | |
1413 | 1413 | while ($words-->0 && $p<$max) |
@@ -1415,13 +1415,13 @@ discard block |
||
1415 | 1415 | list(,$len) = unpack("N*", substr($response, $p, 4)); $p += 4; |
1416 | 1416 | $word = substr($response, $p, $len); $p += $len; |
1417 | 1417 | list($docs, $hits) = array_values(unpack("N*N*", substr($response, $p, 8))); $p += 8; |
1418 | - $result["words"][$word] = array ( |
|
1418 | + $result["words"][$word] = array( |
|
1419 | 1419 | "docs"=>sprintf("%u", $docs), |
1420 | 1420 | "hits"=>sprintf("%u", $hits)); |
1421 | 1421 | } |
1422 | 1422 | } |
1423 | 1423 | |
1424 | - $this->_MBPop (); |
|
1424 | + $this->_MBPop(); |
|
1425 | 1425 | return $results; |
1426 | 1426 | } |
1427 | 1427 | |
@@ -1432,16 +1432,16 @@ discard block |
||
1432 | 1432 | /// connect to searchd server, and generate exceprts (snippets) |
1433 | 1433 | /// of given documents for given query. returns false on failure, |
1434 | 1434 | /// an array of snippets on success |
1435 | - function BuildExcerpts($docs, $index, $words, $opts=array()) |
|
1435 | + function BuildExcerpts($docs, $index, $words, $opts = array()) |
|
1436 | 1436 | { |
1437 | 1437 | assert(is_array($docs)); |
1438 | 1438 | assert(is_string($index)); |
1439 | 1439 | assert(is_string($words)); |
1440 | 1440 | assert(is_array($opts)); |
1441 | 1441 | |
1442 | - $this->_MBPush (); |
|
1442 | + $this->_MBPush(); |
|
1443 | 1443 | |
1444 | - if (!( $fp = $this->_Connect())) |
|
1444 | + if (!($fp = $this->_Connect())) |
|
1445 | 1445 | { |
1446 | 1446 | $this->_MBPop(); |
1447 | 1447 | return false; |
@@ -1490,24 +1490,24 @@ discard block |
||
1490 | 1490 | if ($opts["emit_zones"]) $flags |= 512; |
1491 | 1491 | if ($opts["load_files_scattered"]) $flags |= 1024; |
1492 | 1492 | $req = pack("NN", 0, $flags); // mode=0, flags=$flags |
1493 | - $req .= pack("N", strlen($index)) . $index; // req index |
|
1494 | - $req .= pack("N", strlen($words)) . $words; // req words |
|
1493 | + $req .= pack("N", strlen($index)).$index; // req index |
|
1494 | + $req .= pack("N", strlen($words)).$words; // req words |
|
1495 | 1495 | |
1496 | 1496 | // options |
1497 | - $req .= pack("N", strlen($opts["before_match"])) . $opts["before_match"]; |
|
1498 | - $req .= pack("N", strlen($opts["after_match"])) . $opts["after_match"]; |
|
1499 | - $req .= pack("N", strlen($opts["chunk_separator"])) . $opts["chunk_separator"]; |
|
1497 | + $req .= pack("N", strlen($opts["before_match"])).$opts["before_match"]; |
|
1498 | + $req .= pack("N", strlen($opts["after_match"])).$opts["after_match"]; |
|
1499 | + $req .= pack("N", strlen($opts["chunk_separator"])).$opts["chunk_separator"]; |
|
1500 | 1500 | $req .= pack("NN", (int)$opts["limit"], (int)$opts["around"]); |
1501 | 1501 | $req .= pack("NNN", (int)$opts["limit_passages"], (int)$opts["limit_words"], (int)$opts["start_passage_id"]); // v.1.2 |
1502 | - $req .= pack("N", strlen($opts["html_strip_mode"])) . $opts["html_strip_mode"]; |
|
1503 | - $req .= pack("N", strlen($opts["passage_boundary"])) . $opts["passage_boundary"]; |
|
1502 | + $req .= pack("N", strlen($opts["html_strip_mode"])).$opts["html_strip_mode"]; |
|
1503 | + $req .= pack("N", strlen($opts["passage_boundary"])).$opts["passage_boundary"]; |
|
1504 | 1504 | |
1505 | 1505 | // documents |
1506 | 1506 | $req .= pack("N", count($docs)); |
1507 | 1507 | foreach ($docs as $doc) |
1508 | 1508 | { |
1509 | 1509 | assert(is_string($doc)); |
1510 | - $req .= pack("N", strlen($doc)) . $doc; |
|
1510 | + $req .= pack("N", strlen($doc)).$doc; |
|
1511 | 1511 | } |
1512 | 1512 | |
1513 | 1513 | //////////////////////////// |
@@ -1515,11 +1515,11 @@ discard block |
||
1515 | 1515 | //////////////////////////// |
1516 | 1516 | |
1517 | 1517 | $len = strlen($req); |
1518 | - $req = pack("nnN", SEARCHD_COMMAND_EXCERPT, VER_COMMAND_EXCERPT, $len) . $req; // add header |
|
1519 | - if (!( $this->_Send($fp, $req, $len+8)) || |
|
1520 | - !( $response = $this->_GetResponse($fp, VER_COMMAND_EXCERPT))) |
|
1518 | + $req = pack("nnN", SEARCHD_COMMAND_EXCERPT, VER_COMMAND_EXCERPT, $len).$req; // add header |
|
1519 | + if (!($this->_Send($fp, $req, $len + 8)) || |
|
1520 | + !($response = $this->_GetResponse($fp, VER_COMMAND_EXCERPT))) |
|
1521 | 1521 | { |
1522 | - $this->_MBPop (); |
|
1522 | + $this->_MBPop(); |
|
1523 | 1523 | return false; |
1524 | 1524 | } |
1525 | 1525 | |
@@ -1528,24 +1528,24 @@ discard block |
||
1528 | 1528 | ////////////////// |
1529 | 1529 | |
1530 | 1530 | $pos = 0; |
1531 | - $res = array (); |
|
1531 | + $res = array(); |
|
1532 | 1532 | $rlen = strlen($response); |
1533 | - for($i=0; $i<count($docs); $i++) |
|
1533 | + for ($i = 0; $i<count($docs); $i++) |
|
1534 | 1534 | { |
1535 | 1535 | list(,$len) = unpack("N*", substr($response, $pos, 4)); |
1536 | 1536 | $pos += 4; |
1537 | 1537 | |
1538 | - if ($pos+$len > $rlen) |
|
1538 | + if ($pos + $len>$rlen) |
|
1539 | 1539 | { |
1540 | 1540 | $this->_error = "incomplete reply"; |
1541 | - $this->_MBPop (); |
|
1541 | + $this->_MBPop(); |
|
1542 | 1542 | return false; |
1543 | 1543 | } |
1544 | 1544 | $res[] = $len ? substr($response, $pos, $len) : ""; |
1545 | 1545 | $pos += $len; |
1546 | 1546 | } |
1547 | 1547 | |
1548 | - $this->_MBPop (); |
|
1548 | + $this->_MBPop(); |
|
1549 | 1549 | return $res; |
1550 | 1550 | } |
1551 | 1551 | |
@@ -1563,9 +1563,9 @@ discard block |
||
1563 | 1563 | assert(is_string($index)); |
1564 | 1564 | assert(is_bool($hits)); |
1565 | 1565 | |
1566 | - $this->_MBPush (); |
|
1566 | + $this->_MBPush(); |
|
1567 | 1567 | |
1568 | - if (!( $fp = $this->_Connect())) |
|
1568 | + if (!($fp = $this->_Connect())) |
|
1569 | 1569 | { |
1570 | 1570 | $this->_MBPop(); |
1571 | 1571 | return false; |
@@ -1576,8 +1576,8 @@ discard block |
||
1576 | 1576 | ///////////////// |
1577 | 1577 | |
1578 | 1578 | // v.1.0 req |
1579 | - $req = pack("N", strlen($query)) . $query; // req query |
|
1580 | - $req .= pack("N", strlen($index)) . $index; // req index |
|
1579 | + $req = pack("N", strlen($query)).$query; // req query |
|
1580 | + $req .= pack("N", strlen($index)).$index; // req index |
|
1581 | 1581 | $req .= pack("N", (int)$hits); |
1582 | 1582 | |
1583 | 1583 | //////////////////////////// |
@@ -1585,11 +1585,11 @@ discard block |
||
1585 | 1585 | //////////////////////////// |
1586 | 1586 | |
1587 | 1587 | $len = strlen($req); |
1588 | - $req = pack("nnN", SEARCHD_COMMAND_KEYWORDS, VER_COMMAND_KEYWORDS, $len) . $req; // add header |
|
1589 | - if (!( $this->_Send($fp, $req, $len+8)) || |
|
1590 | - !( $response = $this->_GetResponse($fp, VER_COMMAND_KEYWORDS))) |
|
1588 | + $req = pack("nnN", SEARCHD_COMMAND_KEYWORDS, VER_COMMAND_KEYWORDS, $len).$req; // add header |
|
1589 | + if (!($this->_Send($fp, $req, $len + 8)) || |
|
1590 | + !($response = $this->_GetResponse($fp, VER_COMMAND_KEYWORDS))) |
|
1591 | 1591 | { |
1592 | - $this->_MBPop (); |
|
1592 | + $this->_MBPop(); |
|
1593 | 1593 | return false; |
1594 | 1594 | } |
1595 | 1595 | |
@@ -1598,11 +1598,11 @@ discard block |
||
1598 | 1598 | ////////////////// |
1599 | 1599 | |
1600 | 1600 | $pos = 0; |
1601 | - $res = array (); |
|
1601 | + $res = array(); |
|
1602 | 1602 | $rlen = strlen($response); |
1603 | 1603 | list(,$nwords) = unpack("N*", substr($response, $pos, 4)); |
1604 | 1604 | $pos += 4; |
1605 | - for($i=0; $i<$nwords; $i++) |
|
1605 | + for ($i = 0; $i<$nwords; $i++) |
|
1606 | 1606 | { |
1607 | 1607 | list(,$len) = unpack("N*", substr($response, $pos, 4)); $pos += 4; |
1608 | 1608 | $tokenized = $len ? substr($response, $pos, $len) : ""; |
@@ -1616,28 +1616,28 @@ discard block |
||
1616 | 1616 | |
1617 | 1617 | if ($hits) |
1618 | 1618 | { |
1619 | - list($ndocs,$nhits) = array_values(unpack("N*N*", substr($response, $pos, 8))); |
|
1619 | + list($ndocs, $nhits) = array_values(unpack("N*N*", substr($response, $pos, 8))); |
|
1620 | 1620 | $pos += 8; |
1621 | 1621 | $res [$i]["docs"] = $ndocs; |
1622 | 1622 | $res [$i]["hits"] = $nhits; |
1623 | 1623 | } |
1624 | 1624 | |
1625 | - if ($pos > $rlen) |
|
1625 | + if ($pos>$rlen) |
|
1626 | 1626 | { |
1627 | 1627 | $this->_error = "incomplete reply"; |
1628 | - $this->_MBPop (); |
|
1628 | + $this->_MBPop(); |
|
1629 | 1629 | return false; |
1630 | 1630 | } |
1631 | 1631 | } |
1632 | 1632 | |
1633 | - $this->_MBPop (); |
|
1633 | + $this->_MBPop(); |
|
1634 | 1634 | return $res; |
1635 | 1635 | } |
1636 | 1636 | |
1637 | 1637 | function EscapeString($string) |
1638 | 1638 | { |
1639 | - $from = array('\\', '(',')','|','-','!','@','~','"','&', '/', '^', '$', '=', '<'); |
|
1640 | - $to = array('\\\\', '\(','\)','\|','\-','\!','\@','\~','\"', '\&', '\/', '\^', '\$', '\=', '\<'); |
|
1639 | + $from = array('\\', '(', ')', '|', '-', '!', '@', '~', '"', '&', '/', '^', '$', '=', '<'); |
|
1640 | + $to = array('\\\\', '\(', '\)', '\|', '\-', '\!', '\@', '\~', '\"', '\&', '\/', '\^', '\$', '\=', '\<'); |
|
1641 | 1641 | |
1642 | 1642 | return str_replace($from, $to, $string); |
1643 | 1643 | } |
@@ -1648,7 +1648,7 @@ discard block |
||
1648 | 1648 | |
1649 | 1649 | /// batch update given attributes in given rows in given indexes |
1650 | 1650 | /// returns amount of updated documents (0 or more) on success, or -1 on failure |
1651 | - function UpdateAttributes($index, $attrs, $values, $mva=false, $ignorenonexistent=false) |
|
1651 | + function UpdateAttributes($index, $attrs, $values, $mva = false, $ignorenonexistent = false) |
|
1652 | 1652 | { |
1653 | 1653 | // verify everything |
1654 | 1654 | assert(is_string($index)); |
@@ -1678,14 +1678,14 @@ discard block |
||
1678 | 1678 | } |
1679 | 1679 | |
1680 | 1680 | // build request |
1681 | - $this->_MBPush (); |
|
1682 | - $req = pack("N", strlen($index)) . $index; |
|
1681 | + $this->_MBPush(); |
|
1682 | + $req = pack("N", strlen($index)).$index; |
|
1683 | 1683 | |
1684 | 1684 | $req .= pack("N", count($attrs)); |
1685 | 1685 | $req .= pack("N", $ignorenonexistent ? 1 : 0); |
1686 | 1686 | foreach ($attrs as $attr) |
1687 | 1687 | { |
1688 | - $req .= pack("N", strlen($attr)) . $attr; |
|
1688 | + $req .= pack("N", strlen($attr)).$attr; |
|
1689 | 1689 | $req .= pack("N", $mva ? 1 : 0); |
1690 | 1690 | } |
1691 | 1691 | |
@@ -1703,29 +1703,29 @@ discard block |
||
1703 | 1703 | } |
1704 | 1704 | |
1705 | 1705 | // connect, send query, get response |
1706 | - if (!( $fp = $this->_Connect())) |
|
1706 | + if (!($fp = $this->_Connect())) |
|
1707 | 1707 | { |
1708 | - $this->_MBPop (); |
|
1708 | + $this->_MBPop(); |
|
1709 | 1709 | return -1; |
1710 | 1710 | } |
1711 | 1711 | |
1712 | 1712 | $len = strlen($req); |
1713 | - $req = pack("nnN", SEARCHD_COMMAND_UPDATE, VER_COMMAND_UPDATE, $len) . $req; // add header |
|
1714 | - if (!$this->_Send($fp, $req, $len+8)) |
|
1713 | + $req = pack("nnN", SEARCHD_COMMAND_UPDATE, VER_COMMAND_UPDATE, $len).$req; // add header |
|
1714 | + if (!$this->_Send($fp, $req, $len + 8)) |
|
1715 | 1715 | { |
1716 | - $this->_MBPop (); |
|
1716 | + $this->_MBPop(); |
|
1717 | 1717 | return -1; |
1718 | 1718 | } |
1719 | 1719 | |
1720 | - if (!( $response = $this->_GetResponse($fp, VER_COMMAND_UPDATE))) |
|
1720 | + if (!($response = $this->_GetResponse($fp, VER_COMMAND_UPDATE))) |
|
1721 | 1721 | { |
1722 | - $this->_MBPop (); |
|
1722 | + $this->_MBPop(); |
|
1723 | 1723 | return -1; |
1724 | 1724 | } |
1725 | 1725 | |
1726 | 1726 | // parse response |
1727 | 1727 | list(,$updated) = unpack("N*", substr($response, 0, 4)); |
1728 | - $this->_MBPop (); |
|
1728 | + $this->_MBPop(); |
|
1729 | 1729 | return $updated; |
1730 | 1730 | } |
1731 | 1731 | |
@@ -1735,7 +1735,7 @@ discard block |
||
1735 | 1735 | |
1736 | 1736 | function Open() |
1737 | 1737 | { |
1738 | - if ($this->_socket !== false) |
|
1738 | + if ($this->_socket!==false) |
|
1739 | 1739 | { |
1740 | 1740 | $this->_error = 'already connected'; |
1741 | 1741 | return false; |
@@ -1754,7 +1754,7 @@ discard block |
||
1754 | 1754 | |
1755 | 1755 | function Close() |
1756 | 1756 | { |
1757 | - if ($this->_socket === false) |
|
1757 | + if ($this->_socket===false) |
|
1758 | 1758 | { |
1759 | 1759 | $this->_error = 'not connected'; |
1760 | 1760 | return false; |
@@ -1770,22 +1770,22 @@ discard block |
||
1770 | 1770 | // status |
1771 | 1771 | ////////////////////////////////////////////////////////////////////////// |
1772 | 1772 | |
1773 | - function Status ($session=false) |
|
1773 | + function Status($session = false) |
|
1774 | 1774 | { |
1775 | 1775 | assert(is_bool($session)); |
1776 | 1776 | |
1777 | - $this->_MBPush (); |
|
1778 | - if (!( $fp = $this->_Connect())) |
|
1777 | + $this->_MBPush(); |
|
1778 | + if (!($fp = $this->_Connect())) |
|
1779 | 1779 | { |
1780 | 1780 | $this->_MBPop(); |
1781 | 1781 | return false; |
1782 | 1782 | } |
1783 | 1783 | |
1784 | - $req = pack("nnNN", SEARCHD_COMMAND_STATUS, VER_COMMAND_STATUS, 4, $session?0:1); // len=4, body=1 |
|
1785 | - if (!( $this->_Send($fp, $req, 12)) || |
|
1786 | - !( $response = $this->_GetResponse($fp, VER_COMMAND_STATUS))) |
|
1784 | + $req = pack("nnNN", SEARCHD_COMMAND_STATUS, VER_COMMAND_STATUS, 4, $session ? 0 : 1); // len=4, body=1 |
|
1785 | + if (!($this->_Send($fp, $req, 12)) || |
|
1786 | + !($response = $this->_GetResponse($fp, VER_COMMAND_STATUS))) |
|
1787 | 1787 | { |
1788 | - $this->_MBPop (); |
|
1788 | + $this->_MBPop(); |
|
1789 | 1789 | return false; |
1790 | 1790 | } |
1791 | 1791 | |
@@ -1794,14 +1794,14 @@ discard block |
||
1794 | 1794 | list($rows, $cols) = array_values(unpack("N*N*", substr($response, $p, 8))); $p += 8; |
1795 | 1795 | |
1796 | 1796 | $res = array(); |
1797 | - for($i=0; $i<$rows; $i++) |
|
1798 | - for($j=0; $j<$cols; $j++) |
|
1797 | + for ($i = 0; $i<$rows; $i++) |
|
1798 | + for ($j = 0; $j<$cols; $j++) |
|
1799 | 1799 | { |
1800 | 1800 | list(,$len) = unpack("N*", substr($response, $p, 4)); $p += 4; |
1801 | 1801 | $res[$i][] = substr($response, $p, $len); $p += $len; |
1802 | 1802 | } |
1803 | 1803 | |
1804 | - $this->_MBPop (); |
|
1804 | + $this->_MBPop(); |
|
1805 | 1805 | return $res; |
1806 | 1806 | } |
1807 | 1807 | |
@@ -1809,20 +1809,20 @@ discard block |
||
1809 | 1809 | // flush |
1810 | 1810 | ////////////////////////////////////////////////////////////////////////// |
1811 | 1811 | |
1812 | - function FlushAttributes () |
|
1812 | + function FlushAttributes() |
|
1813 | 1813 | { |
1814 | - $this->_MBPush (); |
|
1815 | - if (!( $fp = $this->_Connect())) |
|
1814 | + $this->_MBPush(); |
|
1815 | + if (!($fp = $this->_Connect())) |
|
1816 | 1816 | { |
1817 | 1817 | $this->_MBPop(); |
1818 | 1818 | return -1; |
1819 | 1819 | } |
1820 | 1820 | |
1821 | 1821 | $req = pack("nnN", SEARCHD_COMMAND_FLUSHATTRS, VER_COMMAND_FLUSHATTRS, 0); // len=0 |
1822 | - if (!( $this->_Send($fp, $req, 8)) || |
|
1823 | - !( $response = $this->_GetResponse($fp, VER_COMMAND_FLUSHATTRS))) |
|
1822 | + if (!($this->_Send($fp, $req, 8)) || |
|
1823 | + !($response = $this->_GetResponse($fp, VER_COMMAND_FLUSHATTRS))) |
|
1824 | 1824 | { |
1825 | - $this->_MBPop (); |
|
1825 | + $this->_MBPop(); |
|
1826 | 1826 | return -1; |
1827 | 1827 | } |
1828 | 1828 | |
@@ -1832,7 +1832,7 @@ discard block |
||
1832 | 1832 | else |
1833 | 1833 | $this->_error = "unexpected response length"; |
1834 | 1834 | |
1835 | - $this->_MBPop (); |
|
1835 | + $this->_MBPop(); |
|
1836 | 1836 | return $tag; |
1837 | 1837 | } |
1838 | 1838 | } |