Completed
Push — master ( 0dda59...7f247a )
by Peter
02:32
created
src/SphinxClient.php 1 patch
Spacing   +228 added lines, -228 removed lines patch added patch discarded remove patch
@@ -33,82 +33,82 @@  discard block
 block discarded – undo
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:
@@ -143,19 +143,19 @@  discard block
 block discarded – undo
143 143
     assert(is_numeric($v));
144 144
 
145 145
     // x64
146
-    if (PHP_INT_SIZE >= 8) {
146
+    if (PHP_INT_SIZE>=8) {
147 147
         $v = (int)$v;
148 148
         return pack('NN', $v >> 32, $v & 0xFFFFFFFF);
149 149
     }
150 150
 
151 151
     // x32, int
152 152
     if (is_int($v)) {
153
-        return pack('NN', $v < 0 ? -1 : 0, $v);
153
+        return pack('NN', $v<0 ? -1 : 0, $v);
154 154
     }
155 155
 
156 156
     // x32, bcmath
157 157
     if (function_exists('bcmul')) {
158
-        if (bccomp($v, 0) == -1) {
158
+        if (bccomp($v, 0)==-1) {
159 159
             $v = bcadd('18446744073709551616', $v);
160 160
         }
161 161
         $h = bcdiv($v, '4294967296', 0);
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
     $l = $m - ($q * 4294967296.0);
174 174
     $h = $hi * 2328.0 + $q; // (10 ^ 13) / (1 << 32) = 2328
175 175
 
176
-    if ($v < 0) {
177
-        if ($l == 0) {
176
+    if ($v<0) {
177
+        if ($l==0) {
178 178
             $h = 4294967296.0 - $h;
179 179
         } else {
180 180
             $h = 4294967295.0 - $h;
@@ -190,8 +190,8 @@  discard block
 block discarded – undo
190 190
     assert(is_numeric($v));
191 191
 
192 192
     // x64
193
-    if (PHP_INT_SIZE >= 8) {
194
-        assert($v >= 0);
193
+    if (PHP_INT_SIZE>=8) {
194
+        assert($v>=0);
195 195
 
196 196
         // x64, int
197 197
         if (is_int($v)) {
@@ -247,16 +247,16 @@  discard block
 block discarded – undo
247 247
 {
248 248
     list($hi, $lo) = array_values(unpack('N*N*', $v));
249 249
 
250
-    if (PHP_INT_SIZE >= 8) {
251
-        if ($hi < 0) { // because php 5.2.2 to 5.2.5 is totally fucked up again
250
+    if (PHP_INT_SIZE>=8) {
251
+        if ($hi<0) { // because php 5.2.2 to 5.2.5 is totally fucked up again
252 252
             $hi += 1 << 32;
253 253
         }
254
-        if ($lo < 0) {
254
+        if ($lo<0) {
255 255
             $lo += 1 << 32;
256 256
         }
257 257
 
258 258
         // x64, int
259
-        if ($hi <= 2147483647) {
259
+        if ($hi<=2147483647) {
260 260
             return ($hi << 32) + $lo;
261 261
         }
262 262
 
@@ -269,20 +269,20 @@  discard block
 block discarded – undo
269 269
         $C = 100000;
270 270
         $h = ((int)($hi / $C) << 32) + (int)($lo / $C);
271 271
         $l = (($hi % $C) << 32) + ($lo % $C);
272
-        if ($l > $C) {
272
+        if ($l>$C) {
273 273
             $h += (int)($l / $C);
274 274
             $l  = $l % $C;
275 275
         }
276 276
 
277
-        if ($h == 0) {
277
+        if ($h==0) {
278 278
             return $l;
279 279
         }
280 280
         return sprintf('%d%05d', $h, $l);
281 281
     }
282 282
 
283 283
     // x32, int
284
-    if ($hi == 0) {
285
-        if ($lo > 0) {
284
+    if ($hi==0) {
285
+        if ($lo>0) {
286 286
             return $lo;
287 287
         }
288 288
         return sprintf('%u', $lo);
@@ -309,10 +309,10 @@  discard block
 block discarded – undo
309 309
 
310 310
     $h = sprintf('%.0f', $h);
311 311
     $l = sprintf('%07.0f', $l);
312
-    if ($h == '0') {
312
+    if ($h=='0') {
313 313
         return sprintf('%.0f', (float)$l);
314 314
     }
315
-    return $h . $l;
315
+    return $h.$l;
316 316
 }
317 317
 
318 318
 // unpack 64-bit signed
@@ -321,24 +321,24 @@  discard block
 block discarded – undo
321 321
     list($hi, $lo) = array_values(unpack('N*N*', $v));
322 322
 
323 323
     // x64
324
-    if (PHP_INT_SIZE >= 8) {
325
-        if ($hi < 0) { // because php 5.2.2 to 5.2.5 is totally fucked up again
324
+    if (PHP_INT_SIZE>=8) {
325
+        if ($hi<0) { // because php 5.2.2 to 5.2.5 is totally fucked up again
326 326
             $hi += 1 << 32;
327 327
         }
328
-        if ($lo < 0) {
328
+        if ($lo<0) {
329 329
             $lo += 1 << 32;
330 330
         }
331 331
 
332 332
         return ($hi << 32) + $lo;
333 333
     }
334 334
 
335
-    if ($hi == 0) { // x32, int
336
-        if ($lo > 0) {
335
+    if ($hi==0) { // x32, int
336
+        if ($lo>0) {
337 337
             return $lo;
338 338
         }
339 339
         return sprintf('%u', $lo);
340
-    } elseif ($hi == -1) { // x32, int
341
-        if ($lo < 0) {
340
+    } elseif ($hi==-1) { // x32, int
341
+        if ($lo<0) {
342 342
             return $lo;
343 343
         }
344 344
         return sprintf('%.0f', $lo - 4294967296.0);
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 
347 347
     $neg = '';
348 348
     $c = 0;
349
-    if ($hi < 0) {
349
+    if ($hi<0) {
350 350
         $hi = ~$hi;
351 351
         $lo = ~$lo;
352 352
         $c = 1;
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 
359 359
     // x32, bcmath
360 360
     if (function_exists('bcmul')) {
361
-        return $neg . bcadd(bcadd($lo, bcmul($hi, '4294967296')), $c);
361
+        return $neg.bcadd(bcadd($lo, bcmul($hi, '4294967296')), $c);
362 362
     }
363 363
 
364 364
     // x32, no-bcmath
@@ -371,25 +371,25 @@  discard block
 block discarded – undo
371 371
     $mq = floor($m / 10000000.0);
372 372
     $l = $m - $mq * 10000000.0 + $c;
373 373
     $h = $q * 4294967296.0 + $r * 429.0 + $mq;
374
-    if ($l == 10000000) {
374
+    if ($l==10000000) {
375 375
         $l = 0;
376 376
         $h += 1;
377 377
     }
378 378
 
379 379
     $h = sprintf('%.0f', $h);
380 380
     $l = sprintf('%07.0f', $l);
381
-    if ($h == '0') {
382
-        return $neg . sprintf('%.0f', (float)$l);
381
+    if ($h=='0') {
382
+        return $neg.sprintf('%.0f', (float)$l);
383 383
     }
384
-    return $neg . $h . $l;
384
+    return $neg.$h.$l;
385 385
 }
386 386
 
387 387
 
388 388
 function sphFixUint($value)
389 389
 {
390
-    if (PHP_INT_SIZE >= 8) {
390
+    if (PHP_INT_SIZE>=8) {
391 391
         // x64 route, workaround broken unpack() in 5.2.2+
392
-        if ($value < 0) {
392
+        if ($value<0) {
393 393
             $value += 1 << 32;
394 394
         }
395 395
         return $value;
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
         $this->warning = '';
508 508
         $this->connerror = false;
509 509
 
510
-        $this->reqs = array();// requests storage (for multi-query case)
510
+        $this->reqs = array(); // requests storage (for multi-query case)
511 511
         $this->mbenc = '';
512 512
         $this->arrayresult = false;
513 513
         $this->timeout = 0;
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
 
516 516
     public function __destruct()
517 517
     {
518
-        if ($this->_socket !== false) {
518
+        if ($this->_socket!==false) {
519 519
             fclose($this->_socket);
520 520
         }
521 521
     }
@@ -542,19 +542,19 @@  discard block
 block discarded – undo
542 542
     public function setServer($host, $port = 0)
543 543
     {
544 544
         assert(is_string($host));
545
-        if ($host[0] == '/') {
546
-            $this->_path = 'unix://' . $host;
545
+        if ($host[0]=='/') {
546
+            $this->_path = 'unix://'.$host;
547 547
             return;
548 548
         }
549
-        if (substr($host, 0, 7) == 'unix://') {
549
+        if (substr($host, 0, 7)=='unix://') {
550 550
             $this->_path = $host;
551 551
             return;
552 552
         }
553 553
 
554 554
         $this->host = $host;
555 555
         $port = intval($port);
556
-        assert(0 <= $port && $port < 65536);
557
-        $this->port = $port == 0 ? 9312 : $port;
556
+        assert(0<=$port && $port<65536);
557
+        $this->port = $port==0 ? 9312 : $port;
558 558
         $this->_path = '';
559 559
     }
560 560
 
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
 
569 569
     protected 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
             $this->error = 'connection unexpectedly closed (timed out?)';
573 573
             $this->connerror = true;
574 574
             return false;
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
     /// connect to searchd server
600 600
     protected function connect()
601 601
     {
602
-        if ($this->_socket !== false) {
602
+        if ($this->_socket!==false) {
603 603
             // we are in persistent connection mode, so we have a socket
604 604
             // however, need to check whether it's still alive
605 605
             if (!@feof($this->_socket)) {
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
             $port = $this->port;
623 623
         }
624 624
 
625
-        if ($this->timeout <= 0) {
625
+        if ($this->timeout<=0) {
626 626
             $fp = @fsockopen($host, $port, $errno, $errstr);
627 627
         } else {
628 628
             $fp = @fsockopen($host, $port, $errno, $errstr, $this->timeout);
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
         // check version
655 655
         list(, $v) = unpack('N*', fread($fp, 4));
656 656
         $v = (int)$v;
657
-        if ($v < 1) {
657
+        if ($v<1) {
658 658
             fclose($fp);
659 659
             $this->error = "expected searchd protocol version 1+, got version '$v'";
660 660
             return false;
@@ -670,10 +670,10 @@  discard block
 block discarded – undo
670 670
         $len = 0;
671 671
 
672 672
         $header = fread($fp, 8);
673
-        if (strlen($header) == 8) {
673
+        if (strlen($header)==8) {
674 674
             list($status, $ver, $len) = array_values(unpack('n2a/Nb', $header));
675 675
             $left = $len;
676
-            while ($left > 0 && !feof($fp)) {
676
+            while ($left>0 && !feof($fp)) {
677 677
                 $chunk = fread($fp, min(8192, $left));
678 678
                 if ($chunk) {
679 679
                     $response .= $chunk;
@@ -681,13 +681,13 @@  discard block
 block discarded – undo
681 681
                 }
682 682
             }
683 683
         }
684
-        if ($this->_socket === false) {
684
+        if ($this->_socket===false) {
685 685
             fclose($fp);
686 686
         }
687 687
 
688 688
         // check response
689 689
         $read = strlen($response);
690
-        if (!$response || $read != $len) {
690
+        if (!$response || $read!=$len) {
691 691
             $this->error = $len
692 692
                 ? "failed to read searchd response (status=$status, ver=$ver, len=$len, read=$read)"
693 693
                 : 'received zero-sized searchd response';
@@ -695,26 +695,26 @@  discard block
 block discarded – undo
695 695
         }
696 696
 
697 697
         // check status
698
-        if ($status == SEARCHD_WARNING) {
698
+        if ($status==SEARCHD_WARNING) {
699 699
             list(, $wlen) = unpack('N*', substr($response, 0, 4));
700 700
             $this->warning = substr($response, 4, $wlen);
701 701
             return substr($response, 4 + $wlen);
702 702
         }
703
-        if ($status == SEARCHD_ERROR) {
704
-            $this->error = 'searchd error: ' . substr($response, 4);
703
+        if ($status==SEARCHD_ERROR) {
704
+            $this->error = 'searchd error: '.substr($response, 4);
705 705
             return false;
706 706
         }
707
-        if ($status == SEARCHD_RETRY) {
708
-            $this->error = 'temporary searchd error: ' . substr($response, 4);
707
+        if ($status==SEARCHD_RETRY) {
708
+            $this->error = 'temporary searchd error: '.substr($response, 4);
709 709
             return false;
710 710
         }
711
-        if ($status != SEARCHD_OK) {
711
+        if ($status!=SEARCHD_OK) {
712 712
             $this->error = "unknown status code '$status'";
713 713
             return false;
714 714
         }
715 715
 
716 716
         // check version
717
-        if ($ver < $client_ver) {
717
+        if ($ver<$client_ver) {
718 718
             $this->warning = sprintf(
719 719
                 'searchd command v.%d.%d older than client\'s v.%d.%d, some options might not work',
720 720
                 $ver >> 8,
@@ -737,15 +737,15 @@  discard block
 block discarded – undo
737 737
     {
738 738
         assert(is_int($offset));
739 739
         assert(is_int($limit));
740
-        assert($offset >= 0);
741
-        assert($limit > 0);
742
-        assert($max >= 0);
740
+        assert($offset>=0);
741
+        assert($limit>0);
742
+        assert($max>=0);
743 743
         $this->offset = $offset;
744 744
         $this->limit = $limit;
745
-        if ($max > 0) {
745
+        if ($max>0) {
746 746
             $this->maxmatches = $max;
747 747
         }
748
-        if ($cutoff > 0) {
748
+        if ($cutoff>0) {
749 749
             $this->cutoff = $cutoff;
750 750
         }
751 751
     }
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
     public function setMaxQueryTime($max)
756 756
     {
757 757
         assert(is_int($max));
758
-        assert($max >= 0);
758
+        assert($max>=0);
759 759
         $this->maxquerytime = $max;
760 760
     }
761 761
 
@@ -767,21 +767,21 @@  discard block
 block discarded – undo
767 767
             E_USER_DEPRECATED
768 768
         );
769 769
         assert(
770
-            $mode == SPH_MATCH_ALL ||
771
-            $mode == SPH_MATCH_ANY ||
772
-            $mode == SPH_MATCH_PHRASE ||
773
-            $mode == SPH_MATCH_BOOLEAN ||
774
-            $mode == SPH_MATCH_EXTENDED ||
775
-            $mode == SPH_MATCH_FULLSCAN ||
776
-            $mode == SPH_MATCH_EXTENDED2
770
+            $mode==SPH_MATCH_ALL ||
771
+            $mode==SPH_MATCH_ANY ||
772
+            $mode==SPH_MATCH_PHRASE ||
773
+            $mode==SPH_MATCH_BOOLEAN ||
774
+            $mode==SPH_MATCH_EXTENDED ||
775
+            $mode==SPH_MATCH_FULLSCAN ||
776
+            $mode==SPH_MATCH_EXTENDED2
777 777
         );
778 778
         $this->mode = $mode;
779 779
     }
780 780
 
781 781
     /// set ranking mode
782
-    public function setRankingMode($ranker, $rankexpr='')
782
+    public function setRankingMode($ranker, $rankexpr = '')
783 783
     {
784
-        assert($ranker === 0 || $ranker >= 1 && $ranker < SPH_RANK_TOTAL);
784
+        assert($ranker===0 || $ranker>=1 && $ranker<SPH_RANK_TOTAL);
785 785
         assert(is_string($rankexpr));
786 786
         $this->ranker = $ranker;
787 787
         $this->rankexpr = $rankexpr;
@@ -790,16 +790,16 @@  discard block
 block discarded – undo
790 790
     /// set matches sorting mode
791 791
     public function setSortMode($mode, $sortby = '')
792 792
     {
793
-        assert (
794
-            $mode == SPH_SORT_RELEVANCE ||
795
-            $mode == SPH_SORT_ATTR_DESC ||
796
-            $mode == SPH_SORT_ATTR_ASC ||
797
-            $mode == SPH_SORT_TIME_SEGMENTS ||
798
-            $mode == SPH_SORT_EXTENDED ||
799
-            $mode == SPH_SORT_EXPR
793
+        assert(
794
+            $mode==SPH_SORT_RELEVANCE ||
795
+            $mode==SPH_SORT_ATTR_DESC ||
796
+            $mode==SPH_SORT_ATTR_ASC ||
797
+            $mode==SPH_SORT_TIME_SEGMENTS ||
798
+            $mode==SPH_SORT_EXTENDED ||
799
+            $mode==SPH_SORT_EXPR
800 800
         );
801 801
         assert(is_string($sortby));
802
-        assert($mode == SPH_SORT_RELEVANCE || strlen($sortby) > 0);
802
+        assert($mode==SPH_SORT_RELEVANCE || strlen($sortby)>0);
803 803
 
804 804
         $this->sort = $mode;
805 805
         $this->sortby = $sortby;
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
     {
844 844
         assert(is_numeric($min));
845 845
         assert(is_numeric($max));
846
-        assert($min <= $max);
846
+        assert($min<=$max);
847 847
         $this->min_id = $min;
848 848
         $this->max_id = $max;
849 849
     }
@@ -891,7 +891,7 @@  discard block
 block discarded – undo
891 891
         assert(is_string($attribute));
892 892
         assert(is_numeric($min));
893 893
         assert(is_numeric($max));
894
-        assert($min <= $max);
894
+        assert($min<=$max);
895 895
 
896 896
         $this->filters[] = array(
897 897
             'type' => SPH_FILTER_RANGE,
@@ -909,7 +909,7 @@  discard block
 block discarded – undo
909 909
         assert(is_string($attribute));
910 910
         assert(is_float($min));
911 911
         assert(is_float($max));
912
-        assert($min <= $max);
912
+        assert($min<=$max);
913 913
 
914 914
         $this->filters[] = array(
915 915
             'type' => SPH_FILTER_FLOATRANGE,
@@ -944,12 +944,12 @@  discard block
 block discarded – undo
944 944
         assert(is_string($attribute));
945 945
         assert(is_string($groupsort));
946 946
         assert(
947
-            $func == SPH_GROUPBY_DAY ||
948
-            $func == SPH_GROUPBY_WEEK ||
949
-            $func == SPH_GROUPBY_MONTH ||
950
-            $func == SPH_GROUPBY_YEAR ||
951
-            $func == SPH_GROUPBY_ATTR ||
952
-            $func == SPH_GROUPBY_ATTRPAIR
947
+            $func==SPH_GROUPBY_DAY ||
948
+            $func==SPH_GROUPBY_WEEK ||
949
+            $func==SPH_GROUPBY_MONTH ||
950
+            $func==SPH_GROUPBY_YEAR ||
951
+            $func==SPH_GROUPBY_ATTR ||
952
+            $func==SPH_GROUPBY_ATTRPAIR
953 953
         );
954 954
 
955 955
         $this->groupby = $attribute;
@@ -967,8 +967,8 @@  discard block
 block discarded – undo
967 967
     /// set distributed retries count and delay
968 968
     public function setRetries($count, $delay = 0)
969 969
     {
970
-        assert(is_int($count) && $count >= 0);
971
-        assert(is_int($delay) && $delay >= 0);
970
+        assert(is_int($count) && $count>=0);
971
+        assert(is_int($delay) && $delay>=0);
972 972
         $this->retrycount = $count;
973 973
         $this->retrydelay = $delay;
974 974
     }
@@ -1025,12 +1025,12 @@  discard block
 block discarded – undo
1025 1025
             'global_idf',
1026 1026
             'low_priority'
1027 1027
         );
1028
-        $flags = array (
1028
+        $flags = array(
1029 1029
             'reverse_scan' => array(0, 1),
1030 1030
             'sort_method' => array('pq', 'kbuffer'),
1031 1031
             'max_predicted_time' => array(0),
1032 1032
             'boolean_simplify' => array(true, false),
1033
-            'idf' => array ('normalized', 'plain', 'tfidf_normalized', 'tfidf_unnormalized'),
1033
+            'idf' => array('normalized', 'plain', 'tfidf_normalized', 'tfidf_unnormalized'),
1034 1034
             'global_idf' => array(true, false),
1035 1035
             'low_priority' => array(true, false)
1036 1036
         );
@@ -1038,32 +1038,32 @@  discard block
 block discarded – undo
1038 1038
         assert(isset($flag_name, $known_names));
1039 1039
         assert(
1040 1040
             in_array($flag_value, $flags[$flag_name], true) ||
1041
-            ($flag_name == 'max_predicted_time' && is_int($flag_value) && $flag_value >= 0)
1041
+            ($flag_name=='max_predicted_time' && is_int($flag_value) && $flag_value>=0)
1042 1042
         );
1043 1043
 
1044
-        if ($flag_name == 'reverse_scan') {
1045
-            $this->query_flags = sphSetBit($this->query_flags, 0, $flag_value == 1);
1044
+        if ($flag_name=='reverse_scan') {
1045
+            $this->query_flags = sphSetBit($this->query_flags, 0, $flag_value==1);
1046 1046
         }
1047
-        if ($flag_name == 'sort_method') {
1048
-            $this->query_flags = sphSetBit($this->query_flags, 1, $flag_value == 'kbuffer');
1047
+        if ($flag_name=='sort_method') {
1048
+            $this->query_flags = sphSetBit($this->query_flags, 1, $flag_value=='kbuffer');
1049 1049
         }
1050
-        if ($flag_name == 'max_predicted_time') {
1051
-            $this->query_flags = sphSetBit($this->query_flags, 2, $flag_value > 0);
1050
+        if ($flag_name=='max_predicted_time') {
1051
+            $this->query_flags = sphSetBit($this->query_flags, 2, $flag_value>0);
1052 1052
             $this->predictedtime = (int)$flag_value;
1053 1053
         }
1054
-        if ($flag_name == 'boolean_simplify') {
1054
+        if ($flag_name=='boolean_simplify') {
1055 1055
             $this->query_flags = sphSetBit($this->query_flags, 3, $flag_value);
1056 1056
         }
1057
-        if ($flag_name == 'idf' && ($flag_value == 'normalized' || $flag_value == 'plain')) {
1058
-            $this->query_flags = sphSetBit($this->query_flags, 4, $flag_value == 'plain');
1057
+        if ($flag_name=='idf' && ($flag_value=='normalized' || $flag_value=='plain')) {
1058
+            $this->query_flags = sphSetBit($this->query_flags, 4, $flag_value=='plain');
1059 1059
         }
1060
-        if ($flag_name == 'global_idf') {
1060
+        if ($flag_name=='global_idf') {
1061 1061
             $this->query_flags = sphSetBit($this->query_flags, 5, $flag_value);
1062 1062
         }
1063
-        if ($flag_name == 'idf' && ($flag_value == 'tfidf_normalized' || $flag_value == 'tfidf_unnormalized')) {
1064
-            $this->query_flags = sphSetBit($this->query_flags, 6, $flag_value == 'tfidf_normalized');
1063
+        if ($flag_name=='idf' && ($flag_value=='tfidf_normalized' || $flag_value=='tfidf_unnormalized')) {
1064
+            $this->query_flags = sphSetBit($this->query_flags, 6, $flag_value=='tfidf_normalized');
1065 1065
         }
1066
-        if ($flag_name == 'low_priority') {
1066
+        if ($flag_name=='low_priority') {
1067 1067
             $this->query_flags = sphSetBit($this->query_flags, 8, $flag_value);
1068 1068
         }
1069 1069
     }
@@ -1074,8 +1074,8 @@  discard block
 block discarded – undo
1074 1074
         assert(is_string($orderby));
1075 1075
         assert(is_int($offset));
1076 1076
         assert(is_int($limit));
1077
-        assert($offset >= 0);
1078
-        assert($limit > 0);
1077
+        assert($offset>=0);
1078
+        assert($limit>0);
1079 1079
 
1080 1080
         $this->outerorderby = $orderby;
1081 1081
         $this->outeroffset = $offset;
@@ -1140,7 +1140,7 @@  discard block
 block discarded – undo
1140 1140
 
1141 1141
         $this->error = $results[0]['error'];
1142 1142
         $this->warning = $results[0]['warning'];
1143
-        if ($results[0]['status'] == SEARCHD_ERROR) {
1143
+        if ($results[0]['status']==SEARCHD_ERROR) {
1144 1144
             return false;
1145 1145
         } else {
1146 1146
             return $results[0];
@@ -1164,24 +1164,24 @@  discard block
 block discarded – undo
1164 1164
 
1165 1165
         // build request
1166 1166
         $req = pack('NNNNN', $this->query_flags, $this->offset, $this->limit, $this->mode, $this->ranker);
1167
-        if ($this->ranker == SPH_RANK_EXPR) {
1168
-            $req .= pack('N', strlen($this->rankexpr)) . $this->rankexpr;
1167
+        if ($this->ranker==SPH_RANK_EXPR) {
1168
+            $req .= pack('N', strlen($this->rankexpr)).$this->rankexpr;
1169 1169
         }
1170 1170
         $req .= pack('N', $this->sort); // (deprecated) sort mode
1171
-        $req .= pack('N', strlen($this->sortby)) . $this->sortby;
1172
-        $req .= pack('N', strlen($query)) . $query; // query itself
1171
+        $req .= pack('N', strlen($this->sortby)).$this->sortby;
1172
+        $req .= pack('N', strlen($query)).$query; // query itself
1173 1173
         $req .= pack('N', count($this->weights)); // weights
1174 1174
         foreach ($this->weights as $weight) {
1175 1175
             $req .= pack('N', (int)$weight);
1176 1176
         }
1177
-        $req .= pack('N', strlen($index)) . $index; // indexes
1177
+        $req .= pack('N', strlen($index)).$index; // indexes
1178 1178
         $req .= pack('N', 1); // id64 range marker
1179
-        $req .= sphPackU64($this->min_id) . sphPackU64($this->max_id); // id64 range
1179
+        $req .= sphPackU64($this->min_id).sphPackU64($this->max_id); // id64 range
1180 1180
 
1181 1181
         // filters
1182 1182
         $req .= pack('N', count($this->filters));
1183 1183
         foreach ($this->filters as $filter) {
1184
-            $req .= pack('N', strlen($filter['attr'])) . $filter['attr'];
1184
+            $req .= pack('N', strlen($filter['attr'])).$filter['attr'];
1185 1185
             $req .= pack('N', $filter['type']);
1186 1186
             switch ($filter['type']) {
1187 1187
                 case SPH_FILTER_VALUES:
@@ -1191,13 +1191,13 @@  discard block
 block discarded – undo
1191 1191
                     }
1192 1192
                     break;
1193 1193
                 case SPH_FILTER_RANGE:
1194
-                    $req .= sphPackI64($filter['min']) . sphPackI64($filter['max']);
1194
+                    $req .= sphPackI64($filter['min']).sphPackI64($filter['max']);
1195 1195
                     break;
1196 1196
                 case SPH_FILTER_FLOATRANGE:
1197
-                    $req .= $this->packFloat($filter['min']) . $this->packFloat($filter['max']);
1197
+                    $req .= $this->packFloat($filter['min']).$this->packFloat($filter['max']);
1198 1198
                     break;
1199 1199
                 case SPH_FILTER_STRING:
1200
-                    $req .= pack('N', strlen($filter['value'])) . $filter['value'];
1200
+                    $req .= pack('N', strlen($filter['value'])).$filter['value'];
1201 1201
                     break;
1202 1202
                 default:
1203 1203
                     assert(0 && 'internal error: unhandled filter type');
@@ -1206,27 +1206,27 @@  discard block
 block discarded – undo
1206 1206
         }
1207 1207
 
1208 1208
         // group-by clause, max-matches count, group-sort clause, cutoff count
1209
-        $req .= pack('NN', $this->groupfunc, strlen($this->groupby)) . $this->groupby;
1209
+        $req .= pack('NN', $this->groupfunc, strlen($this->groupby)).$this->groupby;
1210 1210
         $req .= pack('N', $this->maxmatches);
1211
-        $req .= pack('N', strlen($this->groupsort)) . $this->groupsort;
1211
+        $req .= pack('N', strlen($this->groupsort)).$this->groupsort;
1212 1212
         $req .= pack('NNN', $this->cutoff, $this->retrycount, $this->retrydelay);
1213
-        $req .= pack('N', strlen($this->groupdistinct)) . $this->groupdistinct;
1213
+        $req .= pack('N', strlen($this->groupdistinct)).$this->groupdistinct;
1214 1214
 
1215 1215
         // anchor point
1216 1216
         if (empty($this->anchor)) {
1217 1217
             $req .= pack('N', 0);
1218 1218
         } else {
1219
-            $a =& $this->anchor;
1219
+            $a = & $this->anchor;
1220 1220
             $req .= pack('N', 1);
1221
-            $req .= pack('N', strlen($a['attrlat'])) . $a['attrlat'];
1222
-            $req .= pack('N', strlen($a['attrlong'])) . $a['attrlong'];
1223
-            $req .= $this->packFloat($a['lat']) . $this->packFloat($a['long']);
1221
+            $req .= pack('N', strlen($a['attrlat'])).$a['attrlat'];
1222
+            $req .= pack('N', strlen($a['attrlong'])).$a['attrlong'];
1223
+            $req .= $this->packFloat($a['lat']).$this->packFloat($a['long']);
1224 1224
         }
1225 1225
 
1226 1226
         // per-index weights
1227 1227
         $req .= pack('N', count($this->indexweights));
1228 1228
         foreach ($this->indexweights as $idx => $weight) {
1229
-            $req .= pack('N', strlen($idx)) . $idx . pack('N', $weight);
1229
+            $req .= pack('N', strlen($idx)).$idx.pack('N', $weight);
1230 1230
         }
1231 1231
 
1232 1232
         // max query time
@@ -1235,16 +1235,16 @@  discard block
 block discarded – undo
1235 1235
         // per-field weights
1236 1236
         $req .= pack('N', count($this->fieldweights));
1237 1237
         foreach ($this->fieldweights as $field => $weight) {
1238
-            $req .= pack('N', strlen($field)) . $field . pack('N', $weight);
1238
+            $req .= pack('N', strlen($field)).$field.pack('N', $weight);
1239 1239
         }
1240 1240
 
1241 1241
         // comment
1242
-        $req .= pack('N', strlen($comment)) . $comment;
1242
+        $req .= pack('N', strlen($comment)).$comment;
1243 1243
 
1244 1244
         // attribute overrides
1245 1245
         $req .= pack('N', count($this->overrides));
1246 1246
         foreach ($this->overrides as $key => $entry) {
1247
-            $req .= pack('N', strlen($entry['attr'])) . $entry['attr'];
1247
+            $req .= pack('N', strlen($entry['attr'])).$entry['attr'];
1248 1248
             $req .= pack('NN', $entry['type'], count($entry['values']));
1249 1249
             foreach ($entry['values'] as $id => $val) {
1250 1250
                 assert(is_numeric($id));
@@ -1266,14 +1266,14 @@  discard block
 block discarded – undo
1266 1266
         }
1267 1267
 
1268 1268
         // select-list
1269
-        $req .= pack('N', strlen($this->select)) . $this->select;
1269
+        $req .= pack('N', strlen($this->select)).$this->select;
1270 1270
 
1271 1271
         // max_predicted_time
1272
-        if ($this->predictedtime > 0) {
1272
+        if ($this->predictedtime>0) {
1273 1273
             $req .= pack('N', (int)$this->predictedtime);
1274 1274
         }
1275 1275
 
1276
-        $req .= pack('N', strlen($this->outerorderby)) . $this->outerorderby;
1276
+        $req .= pack('N', strlen($this->outerorderby)).$this->outerorderby;
1277 1277
         $req .= pack('NN', $this->outeroffset, $this->outerlimit);
1278 1278
         if ($this->hasouter) {
1279 1279
             $req .= pack('N', 1);
@@ -1309,7 +1309,7 @@  discard block
 block discarded – undo
1309 1309
         $nreqs = count($this->reqs);
1310 1310
         $req = join('', $this->reqs);
1311 1311
         $len = 8 + strlen($req);
1312
-        $req = pack('nnNNN', SEARCHD_COMMAND_SEARCH, VER_COMMAND_SEARCH, $len, 0, $nreqs) . $req; // add header
1312
+        $req = pack('nnNNN', SEARCHD_COMMAND_SEARCH, VER_COMMAND_SEARCH, $len, 0, $nreqs).$req; // add header
1313 1313
 
1314 1314
         if (!$this->send($fp, $req, $len + 8) || !($response = $this->getResponse($fp, VER_COMMAND_SEARCH))) {
1315 1315
             $this->mbPop();
@@ -1330,9 +1330,9 @@  discard block
 block discarded – undo
1330 1330
         $max = strlen($response); // max position for checks, to protect against broken responses
1331 1331
 
1332 1332
         $results = array();
1333
-        for ($ires = 0; $ires < $nreqs && $p < $max; $ires++) {
1333
+        for ($ires = 0; $ires<$nreqs && $p<$max; $ires++) {
1334 1334
             $results[] = array();
1335
-            $result =& $results[$ires];
1335
+            $result = & $results[$ires];
1336 1336
 
1337 1337
             $result['error'] = '';
1338 1338
             $result['warning'] = '';
@@ -1341,13 +1341,13 @@  discard block
 block discarded – undo
1341 1341
             list(, $status) = unpack('N*', substr($response, $p, 4));
1342 1342
             $p += 4;
1343 1343
             $result['status'] = $status;
1344
-            if ($status != SEARCHD_OK) {
1344
+            if ($status!=SEARCHD_OK) {
1345 1345
                 list(, $len) = unpack('N*', substr($response, $p, 4));
1346 1346
                 $p += 4;
1347 1347
                 $message = substr($response, $p, $len);
1348 1348
                 $p += $len;
1349 1349
 
1350
-                if ($status == SEARCHD_WARNING) {
1350
+                if ($status==SEARCHD_WARNING) {
1351 1351
                     $result['warning'] = $message;
1352 1352
                 } else {
1353 1353
                     $result['error'] = $message;
@@ -1361,7 +1361,7 @@  discard block
 block discarded – undo
1361 1361
 
1362 1362
             list(, $nfields) = unpack('N*', substr($response, $p, 4));
1363 1363
             $p += 4;
1364
-            while ($nfields --> 0 && $p < $max) {
1364
+            while ($nfields-->0 && $p<$max) {
1365 1365
                 list(, $len) = unpack('N*', substr($response, $p, 4));
1366 1366
                 $p += 4;
1367 1367
                 $fields[] = substr($response, $p, $len);
@@ -1371,7 +1371,7 @@  discard block
 block discarded – undo
1371 1371
 
1372 1372
             list(, $nattrs) = unpack('N*', substr($response, $p, 4));
1373 1373
             $p += 4;
1374
-            while ($nattrs --> 0 && $p < $max) {
1374
+            while ($nattrs-->0 && $p<$max) {
1375 1375
                 list(, $len) = unpack('N*', substr($response, $p, 4));
1376 1376
                 $p += 4;
1377 1377
                 $attr = substr($response, $p, $len);
@@ -1390,7 +1390,7 @@  discard block
 block discarded – undo
1390 1390
 
1391 1391
             // read matches
1392 1392
             $idx = -1;
1393
-            while ($count --> 0 && $p < $max) {
1393
+            while ($count-->0 && $p<$max) {
1394 1394
                 // index into result array
1395 1395
                 $idx++;
1396 1396
 
@@ -1418,14 +1418,14 @@  discard block
 block discarded – undo
1418 1418
                 $attrvals = array();
1419 1419
                 foreach ($attrs as $attr => $type) {
1420 1420
                     // handle 64bit ints
1421
-                    if ($type == SPH_ATTR_BIGINT) {
1421
+                    if ($type==SPH_ATTR_BIGINT) {
1422 1422
                         $attrvals[$attr] = sphUnpackI64(substr($response, $p, 8));
1423 1423
                         $p += 8;
1424 1424
                         continue;
1425 1425
                     }
1426 1426
 
1427 1427
                     // handle floats
1428
-                    if ($type == SPH_ATTR_FLOAT) {
1428
+                    if ($type==SPH_ATTR_FLOAT) {
1429 1429
                         list(, $uval) = unpack('N*', substr($response, $p, 4));
1430 1430
                         $p += 4;
1431 1431
                         list(, $fval) = unpack('f*', pack('L', $uval));
@@ -1436,28 +1436,28 @@  discard block
 block discarded – undo
1436 1436
                     // handle everything else as unsigned ints
1437 1437
                     list(, $val) = unpack('N*', substr($response, $p, 4));
1438 1438
                     $p += 4;
1439
-                    if ($type == SPH_ATTR_MULTI) {
1439
+                    if ($type==SPH_ATTR_MULTI) {
1440 1440
                         $attrvals[$attr] = array();
1441 1441
                         $nvalues = $val;
1442
-                        while ($nvalues --> 0 && $p < $max) {
1442
+                        while ($nvalues-->0 && $p<$max) {
1443 1443
                             list(, $val) = unpack('N*', substr($response, $p, 4));
1444 1444
                             $p += 4;
1445 1445
                             $attrvals[$attr][] = sphFixUint($val);
1446 1446
                         }
1447
-                    } elseif ($type == SPH_ATTR_MULTI64) {
1447
+                    } elseif ($type==SPH_ATTR_MULTI64) {
1448 1448
                         $attrvals[$attr] = array();
1449 1449
                         $nvalues = $val;
1450
-                        while ($nvalues > 0 && $p < $max) {
1450
+                        while ($nvalues>0 && $p<$max) {
1451 1451
                             $attrvals[$attr][] = sphUnpackI64(substr($response, $p, 8));
1452 1452
                             $p += 8;
1453 1453
                             $nvalues -= 2;
1454 1454
                         }
1455
-                    } elseif ($type == SPH_ATTR_STRING) {
1455
+                    } elseif ($type==SPH_ATTR_STRING) {
1456 1456
                         $attrvals[$attr] = substr($response, $p, $val);
1457 1457
                         $p += $val;
1458
-                    } elseif ($type == SPH_ATTR_FACTORS) {
1458
+                    } elseif ($type==SPH_ATTR_FACTORS) {
1459 1459
                         $attrvals[$attr] = substr($response, $p, $val - 4);
1460
-                        $p += $val-4;
1460
+                        $p += $val - 4;
1461 1461
                     } else {
1462 1462
                         $attrvals[$attr] = sphFixUint($val);
1463 1463
                     }
@@ -1476,14 +1476,14 @@  discard block
 block discarded – undo
1476 1476
             $result['time'] = sprintf('%.3f', $msecs / 1000);
1477 1477
             $p += 16;
1478 1478
 
1479
-            while ($words --> 0 && $p < $max) {
1479
+            while ($words-->0 && $p<$max) {
1480 1480
                 list(, $len) = unpack('N*', substr($response, $p, 4));
1481 1481
                 $p += 4;
1482 1482
                 $word = substr($response, $p, $len);
1483 1483
                 $p += $len;
1484 1484
                 list($docs, $hits) = array_values(unpack('N*N*', substr($response, $p, 8)));
1485 1485
                 $p += 8;
1486
-                $result['words'][$word] = array (
1486
+                $result['words'][$word] = array(
1487 1487
                     'docs' => sprintf('%u', $docs),
1488 1488
                     'hits' => sprintf('%u', $hits)
1489 1489
                 );
@@ -1618,23 +1618,23 @@  discard block
 block discarded – undo
1618 1618
             $flags |= 1024;
1619 1619
         }
1620 1620
         $req = pack('NN', 0, $flags); // mode=0, flags=$flags
1621
-        $req .= pack('N', strlen($index)) . $index; // req index
1622
-        $req .= pack('N', strlen($words)) . $words; // req words
1621
+        $req .= pack('N', strlen($index)).$index; // req index
1622
+        $req .= pack('N', strlen($words)).$words; // req words
1623 1623
 
1624 1624
         // options
1625
-        $req .= pack('N', strlen($opts['before_match'])) . $opts['before_match'];
1626
-        $req .= pack('N', strlen($opts['after_match'])) . $opts['after_match'];
1627
-        $req .= pack('N', strlen($opts['chunk_separator'])) . $opts['chunk_separator'];
1625
+        $req .= pack('N', strlen($opts['before_match'])).$opts['before_match'];
1626
+        $req .= pack('N', strlen($opts['after_match'])).$opts['after_match'];
1627
+        $req .= pack('N', strlen($opts['chunk_separator'])).$opts['chunk_separator'];
1628 1628
         $req .= pack('NN', (int)$opts['limit'], (int)$opts['around']);
1629 1629
         $req .= pack('NNN', (int)$opts['limit_passages'], (int)$opts['limit_words'], (int)$opts['start_passage_id']); // v.1.2
1630
-        $req .= pack('N', strlen($opts['html_strip_mode'])) . $opts['html_strip_mode'];
1631
-        $req .= pack('N', strlen($opts['passage_boundary'])) . $opts['passage_boundary'];
1630
+        $req .= pack('N', strlen($opts['html_strip_mode'])).$opts['html_strip_mode'];
1631
+        $req .= pack('N', strlen($opts['passage_boundary'])).$opts['passage_boundary'];
1632 1632
 
1633 1633
         // documents
1634 1634
         $req .= pack('N', count($docs));
1635 1635
         foreach ($docs as $doc) {
1636 1636
             assert(is_string($doc));
1637
-            $req .= pack('N', strlen($doc)) . $doc;
1637
+            $req .= pack('N', strlen($doc)).$doc;
1638 1638
         }
1639 1639
 
1640 1640
         ////////////////////////////
@@ -1642,7 +1642,7 @@  discard block
 block discarded – undo
1642 1642
         ////////////////////////////
1643 1643
 
1644 1644
         $len = strlen($req);
1645
-        $req = pack('nnN', SEARCHD_COMMAND_EXCERPT, VER_COMMAND_EXCERPT, $len) . $req; // add header
1645
+        $req = pack('nnN', SEARCHD_COMMAND_EXCERPT, VER_COMMAND_EXCERPT, $len).$req; // add header
1646 1646
         if (!$this->send($fp, $req, $len + 8) || !($response = $this->getResponse($fp, VER_COMMAND_EXCERPT))) {
1647 1647
             $this->mbPop();
1648 1648
             return false;
@@ -1660,7 +1660,7 @@  discard block
 block discarded – undo
1660 1660
             list(, $len) = unpack('N*', substr($response, $pos, 4));
1661 1661
             $pos += 4;
1662 1662
 
1663
-            if ($pos + $len > $rlen) {
1663
+            if ($pos + $len>$rlen) {
1664 1664
                 $this->error = 'incomplete reply';
1665 1665
                 $this->mbPop();
1666 1666
                 return false;
@@ -1699,8 +1699,8 @@  discard block
 block discarded – undo
1699 1699
         /////////////////
1700 1700
 
1701 1701
         // v.1.0 req
1702
-        $req  = pack('N', strlen($query)) . $query; // req query
1703
-        $req .= pack('N', strlen($index)) . $index; // req index
1702
+        $req  = pack('N', strlen($query)).$query; // req query
1703
+        $req .= pack('N', strlen($index)).$index; // req index
1704 1704
         $req .= pack('N', (int)$hits);
1705 1705
 
1706 1706
         ////////////////////////////
@@ -1708,7 +1708,7 @@  discard block
 block discarded – undo
1708 1708
         ////////////////////////////
1709 1709
 
1710 1710
         $len = strlen($req);
1711
-        $req = pack('nnN', SEARCHD_COMMAND_KEYWORDS, VER_COMMAND_KEYWORDS, $len) . $req; // add header
1711
+        $req = pack('nnN', SEARCHD_COMMAND_KEYWORDS, VER_COMMAND_KEYWORDS, $len).$req; // add header
1712 1712
         if (!$this->send($fp, $req, $len + 8) || !($response = $this->getResponse($fp, VER_COMMAND_KEYWORDS))) {
1713 1713
             $this->mbPop();
1714 1714
             return false;
@@ -1723,7 +1723,7 @@  discard block
 block discarded – undo
1723 1723
         $rlen = strlen($response);
1724 1724
         list(, $nwords) = unpack('N*', substr($response, $pos, 4));
1725 1725
         $pos += 4;
1726
-        for ($i = 0; $i < $nwords; $i++) {
1726
+        for ($i = 0; $i<$nwords; $i++) {
1727 1727
             list(, $len) = unpack('N*', substr($response, $pos, 4));
1728 1728
             $pos += 4;
1729 1729
             $tokenized = $len ? substr($response, $pos, $len) : '';
@@ -1746,7 +1746,7 @@  discard block
 block discarded – undo
1746 1746
                 $res[$i]['hits'] = $nhits;
1747 1747
             }
1748 1748
 
1749
-            if ($pos > $rlen) {
1749
+            if ($pos>$rlen) {
1750 1750
                 $this->error = 'incomplete reply';
1751 1751
                 $this->mbPop();
1752 1752
                 return false;
@@ -1759,8 +1759,8 @@  discard block
 block discarded – undo
1759 1759
 
1760 1760
     public function escapeString($string)
1761 1761
     {
1762
-        $from = array('\\', '(',')','|','-','!','@','~','"','&', '/', '^', '$', '=', '<');
1763
-        $to   = array('\\\\', '\(','\)','\|','\-','\!','\@','\~','\"', '\&', '\/', '\^', '\$', '\=', '\<');
1762
+        $from = array('\\', '(', ')', '|', '-', '!', '@', '~', '"', '&', '/', '^', '$', '=', '<');
1763
+        $to   = array('\\\\', '\(', '\)', '\|', '\-', '\!', '\@', '\~', '\"', '\&', '\/', '\^', '\$', '\=', '\<');
1764 1764
 
1765 1765
         return str_replace($from, $to, $string);
1766 1766
     }
@@ -1787,7 +1787,7 @@  discard block
 block discarded – undo
1787 1787
         foreach ($values as $id => $entry) {
1788 1788
             assert(is_numeric($id));
1789 1789
             assert(is_array($entry));
1790
-            assert(count($entry) == count($attrs));
1790
+            assert(count($entry)==count($attrs));
1791 1791
             foreach ($entry as $v) {
1792 1792
                 if ($mva) {
1793 1793
                     assert(is_array($v));
@@ -1802,12 +1802,12 @@  discard block
 block discarded – undo
1802 1802
 
1803 1803
         // build request
1804 1804
         $this->mbPush();
1805
-        $req = pack('N', strlen($index)) . $index;
1805
+        $req = pack('N', strlen($index)).$index;
1806 1806
 
1807 1807
         $req .= pack('N', count($attrs));
1808 1808
         $req .= pack('N', $ignorenonexistent ? 1 : 0);
1809 1809
         foreach ($attrs as $attr) {
1810
-            $req .= pack('N', strlen($attr)) . $attr;
1810
+            $req .= pack('N', strlen($attr)).$attr;
1811 1811
             $req .= pack('N', $mva ? 1 : 0);
1812 1812
         }
1813 1813
 
@@ -1831,7 +1831,7 @@  discard block
 block discarded – undo
1831 1831
         }
1832 1832
 
1833 1833
         $len = strlen($req);
1834
-        $req = pack('nnN', SEARCHD_COMMAND_UPDATE, VER_COMMAND_UPDATE, $len) . $req; // add header
1834
+        $req = pack('nnN', SEARCHD_COMMAND_UPDATE, VER_COMMAND_UPDATE, $len).$req; // add header
1835 1835
         if (!$this->send($fp, $req, $len + 8)) {
1836 1836
             $this->mbPop();
1837 1837
             return -1;
@@ -1854,7 +1854,7 @@  discard block
 block discarded – undo
1854 1854
 
1855 1855
     public function open()
1856 1856
     {
1857
-        if ($this->_socket !== false) {
1857
+        if ($this->_socket!==false) {
1858 1858
             $this->error = 'already connected';
1859 1859
             return false;
1860 1860
         }
@@ -1873,7 +1873,7 @@  discard block
 block discarded – undo
1873 1873
 
1874 1874
     public function close()
1875 1875
     {
1876
-        if ($this->_socket === false) {
1876
+        if ($this->_socket===false) {
1877 1877
             $this->error = 'not connected';
1878 1878
             return false;
1879 1879
         }
@@ -1910,8 +1910,8 @@  discard block
 block discarded – undo
1910 1910
         $p += 8;
1911 1911
 
1912 1912
         $res = array();
1913
-        for ($i = 0; $i < $rows; $i++) {
1914
-            for ($j = 0; $j < $cols; $j++) {
1913
+        for ($i = 0; $i<$rows; $i++) {
1914
+            for ($j = 0; $j<$cols; $j++) {
1915 1915
                 list(, $len) = unpack('N*', substr($response, $p, 4));
1916 1916
                 $p += 4;
1917 1917
                 $res[$i][] = substr($response, $p, $len);
@@ -1942,7 +1942,7 @@  discard block
 block discarded – undo
1942 1942
         }
1943 1943
 
1944 1944
         $tag = -1;
1945
-        if (strlen($response) == 4) {
1945
+        if (strlen($response)==4) {
1946 1946
             list(, $tag) = unpack('N*', $response);
1947 1947
         } else {
1948 1948
             $this->error = 'unexpected response length';
Please login to merge, or discard this patch.
src/test.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
     $select = '';
75 75
     $count = count($args);
76 76
 
77
-    for ($i = 0; $i < $count; $i++) {
77
+    for ($i = 0; $i<$count; $i++) {
78 78
         switch ($args[$i]) {
79 79
             case '-h':
80 80
             case '--host':
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
                 }
169 169
                 break;
170 170
             default:
171
-                $q .= $args[$i] . ' ';
171
+                $q .= $args[$i].' ';
172 172
         }
173 173
     }
174 174
 
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
         $cl->setSelect($select);
200 200
     }
201 201
     if ($limit) {
202
-        $cl->setLimits(0, $limit, ($limit > 1000) ? $limit : 1000);
202
+        $cl->setLimits(0, $limit, ($limit>1000) ? $limit : 1000);
203 203
     }
204 204
     $cl->setRankingMode($ranker);
205 205
     $res = $cl->query($q, $index);
@@ -208,16 +208,16 @@  discard block
 block discarded – undo
208 208
     // print me out
209 209
     ////////////////
210 210
 
211
-    if ($res === false) {
212
-        printf('Query failed: %s.' . PHP_EOL, $cl->getLastError());
211
+    if ($res===false) {
212
+        printf('Query failed: %s.'.PHP_EOL, $cl->getLastError());
213 213
 
214 214
     } else {
215 215
         if ($cl->getLastWarning()) {
216
-            printf('WARNING: %s' . PHP_EOL . PHP_EOL, $cl->getLastWarning());
216
+            printf('WARNING: %s'.PHP_EOL.PHP_EOL, $cl->getLastWarning());
217 217
         }
218 218
 
219 219
         print "Query '$q' retrieved {$res['total']} of {$res['total_found']} matches in {$res['time']} sec.\n";
220
-        print 'Query stats:' . PHP_EOL;
220
+        print 'Query stats:'.PHP_EOL;
221 221
         if (is_array($res['words'])) {
222 222
             foreach ($res['words'] as $word => $info) {
223 223
                 print "    '$word' found {$info['hits']} times in {$info['docs']} documents\n";
@@ -227,14 +227,14 @@  discard block
 block discarded – undo
227 227
 
228 228
         if (is_array($res['matches'])) {
229 229
             $n = 1;
230
-            print 'Matches:' . PHP_EOL;
230
+            print 'Matches:'.PHP_EOL;
231 231
             foreach ($res['matches'] as $docinfo) {
232 232
                 print "$n. doc_id={$docinfo['id']}, weight={$docinfo['weight']}";
233 233
                 foreach ($res['attrs'] as $attrname => $attrtype) {
234 234
                     $value = $docinfo['attrs'][$attrname];
235
-                    if ($attrtype == SPH_ATTR_MULTI || $attrtype == SPH_ATTR_MULTI64) {
236
-                        $value = '(' . join(',', $value) . ')';
237
-                    } elseif ($attrtype == SPH_ATTR_TIMESTAMP) {
235
+                    if ($attrtype==SPH_ATTR_MULTI || $attrtype==SPH_ATTR_MULTI64) {
236
+                        $value = '('.join(',', $value).')';
237
+                    } elseif ($attrtype==SPH_ATTR_TIMESTAMP) {
238 238
                         $value = date('Y-m-d H:i:s', $value);
239 239
                     }
240 240
                     print ", $attrname=$value";
Please login to merge, or discard this patch.