Lines Matching +full:l +full:- +full:max

4 // $Id: sphinxapi.php 2055 2009-11-06 23:09:58Z shodan $
8 // Copyright (c) 2001-2008, Andrew Aksyonoff. All rights reserved.
29 /// current client-side command implementation versions
56 define("SPH_RANK_WORDCOUNT", 3); ///< simple word-count weighting, rank is a weighted sum of per-f…
92 // - always signed (one bit short of PHP_INT_SIZE)
93 // - conversion from string to int is saturated
94 // - float is double
95 // - div converts arguments to floats
96 // - mod converts arguments to ints
99 // - when we got an int, just pack it
102 // - otherwise, we got a number in string form
106 // - factor the string into high and low ints for packing
107 // - if we have bcmath, then it is used
108 // - if we don't, we have to do it manually (this is the fun part)
110 // - x64 branch does factoring using ints
111 // - x32 (ab)uses floats, since we can't fit unsigned 32-bit number into an int
114 // - return ints if we can
115 // - otherwise format number into a string
117 /// pack 64-bit signed
130 return pack("NN", $v < 0 ? -1 : 0, $v);
134 if (bccomp($v, 0) == -1)
137 $l = bcmod($v, "4294967296");
138 …return pack("NN", (float)$h, (float)$l); // conversion to float is intentional; int would lose 31s…
141 // x32, no-bcmath
142 $p = max(0, strlen($v) - 13);
148 $l = $m - ($q * 4294967296.0);
152 if ($l == 0)
153 $h = 4294967296.0 - $h;
155 $h = 4294967295.0 - $h;
156 $l = 4294967296.0 - $l;
159 return pack("NN", $h, $l);
162 /// pack 64-bit unsigned
178 $l = bcmod($v, 4294967296);
179 return pack("NN", $h, $l);
182 // x64, no-bcmath
183 $p = max(0, strlen($v) - 13);
188 $l = $m % 4294967296;
191 return pack("NN", $h, $l);
201 $l = bcmod($v, "4294967296");
202 …return pack("NN", (float)$h, (float)$l); // conversion to float is intentional; int would lose 31s…
205 // x32, no-bcmath
206 $p = max(0, strlen($v) - 13);
212 $l = $m - ($q * 4294967296.0);
215 return pack("NN", $h, $l);
218 // unpack 64-bit unsigned
235 // x64, no-bcmath
238 $l = (($hi % $C) << 32) + ($lo % $C);
239 if ($l > $C) {
240 $h += (int)($l / $C);
241 $l = $l % $C;
245 return $l;
246 return sprintf("%d%05d", $h, $l);
263 // x32, no-bcmath
268 $r = $hi - $q * 10000000.0;
271 $l = $m - $mq * 10000000.0;
275 $l = sprintf("%07.0f", $l);
277 return sprintf("%.0f", (float)$l);
278 return $h . $l;
281 // unpack 64-bit signed
301 elseif ($hi == -1) {
304 return sprintf("%.0f", $lo - 4294967296.0);
313 $neg = "-";
323 // x32, no-bcmath
328 $r = $hi - $q * 10000000.0;
331 $l = $m - $mq * 10000000.0 + $c;
333 if ($l == 10000000) {
334 $l = 0;
339 $l = sprintf("%07.0f", $l);
341 return $neg . sprintf("%.0f", (float)$l);
342 return $neg . $h . $l;
364 var $_offset; ///< how many records to seek from result-set start (default is 0)
365 var $_limit; ///< how many records to return from result-set starting at offset (default is 20)
367 var $_weights; ///< per-field weights (default is 1 for all fields)
371 var $_max_id; ///< max ID to match (default is 0, which means no limit)
373 var $_groupby; ///< group-by attribute name
374 var $_groupfunc; ///< group-by function (to pre-process group-by attribute value with)
375 var $_groupsort; ///< group-by sorting clause (to sort groups in result set with)
376 var $_groupdistinct; ///< group-by count-distinct attribute
377 var $_maxmatches; ///< max matches to retrieve
382 var $_indexweights; ///< per-index weights
384 var $_maxquerytime; ///< max query time, milliseconds (default is 0, do not limit)
385 var $_fieldweights; ///< per-field-name weights
386 var $_overrides; ///< per-query attribute values overrides
387 var $_select; ///< select-list (attributes or expressions, with optional aliases)
393 var $_reqs; ///< requests array for multi-query
405 // per-client-object settings
406 $this->_host = "localhost";
407 $this->_port = 9312;
408 $this->_path = false;
409 $this->_socket = false;
411 // per-query settings
412 $this->_offset = 0;
413 $this->_limit = 20;
414 $this->_mode = SPH_MATCH_ALL;
415 $this->_weights = array();
416 $this->_sort = SPH_SORT_RELEVANCE;
417 $this->_sortby = "";
418 $this->_min_id = 0;
419 $this->_max_id = 0;
420 $this->_filters = array();
421 $this->_groupby = "";
422 $this->_groupfunc = SPH_GROUPBY_DAY;
423 $this->_groupsort = "@group desc";
424 $this->_groupdistinct = "";
425 $this->_maxmatches = 1000;
426 $this->_cutoff = 0;
427 $this->_retrycount = 0;
428 $this->_retrydelay = 0;
429 $this->_anchor = array();
430 $this->_indexweights = array();
431 $this->_ranker = SPH_RANK_PROXIMITY_BM25;
432 $this->_maxquerytime = 0;
433 $this->_fieldweights = array();
434 $this->_overrides = array();
435 $this->_select = "*";
437 $this->_error = ""; // per-reply fields (for single-query case)
438 $this->_warning = "";
439 $this->_connerror = false;
441 $this->_reqs = array(); // requests storage (for multi-query case)
442 $this->_mbenc = "";
443 $this->_arrayresult = false;
444 $this->_timeout = 0;
449 if ($this->_socket !== false)
450 fclose($this->_socket);
456 return $this->_error;
462 return $this->_warning;
468 return $this->_connerror;
476 $this->_path = 'unix://' . $host;
480 $this->_path = $host;
485 $this->_host = $host;
486 $this->_port = $port;
487 $this->_path = '';
494 $this->_timeout = $timeout;
501 $this->_error = 'connection unexpectedly closed (timed out?)';
502 $this->_connerror = true;
513 $this->_mbenc = "";
515 $this->_mbenc = mb_internal_encoding();
523 if ($this->_mbenc)
524 mb_internal_encoding($this->_mbenc);
530 if ($this->_socket !== false) {
533 if (!@feof($this->_socket))
534 return $this->_socket;
537 $this->_socket = false;
542 $this->_connerror = false;
544 if ($this->_path) {
545 $host = $this->_path;
548 $host = $this->_host;
549 $port = $this->_port;
552 if ($this->_timeout <= 0)
555 $fp = @fsockopen($host, $port, $errno, $errstr, $this->_timeout);
558 if ($this->_path)
559 $location = $this->_path;
561 $location = "{$this->_host}:{$this->_port}";
564 $this->_error = "connection to $location failed (errno=$errno, msg=$errstr)";
565 $this->_connerror = true;
572 // TCP stack could throttle write-write-read pattern because of Nagle.
573 if (!$this->_Send($fp, pack("N", 1), 4)) {
575 $this->_error = "failed to send client protocol version";
584 $this->_error = "expected searchd protocol version 1+, got version '$v'";
605 $left -= strlen($chunk);
609 if ($this->_socket === false)
615 $this->_error = $len
617 : "received zero-sized searchd response";
624 $this->_warning = substr($response, 4, $wlen);
628 $this->_error = "searchd error: " . substr($response, 4);
632 $this->_error = "temporary searchd error: " . substr($response, 4);
636 $this->_error = "unknown status code '$status'";
642 $this->_warning = sprintf(
659 /// and optionally set max-matches and cutoff limits
660 function SetLimits($offset, $limit, $max = 0, $cutoff = 0) argument
666 assert($max >= 0);
667 $this->_offset = $offset;
668 $this->_limit = $limit;
669 if ($max > 0)
670 $this->_maxmatches = $max;
672 $this->_cutoff = $cutoff;
675 /// set maximum query time, in milliseconds, per-index
677 function SetMaxQueryTime($max) argument
679 assert(is_int($max));
680 assert($max >= 0);
681 $this->_maxquerytime = $max;
694 $this->_mode = $mode;
705 $this->_ranker = $ranker;
722 $this->_sort = $mode;
723 $this->_sortby = $sortby;
726 /// bind per-field weights by order
734 $this->_weights = $weights;
737 /// bind per-field weights by name
745 $this->_fieldweights = $weights;
748 /// bind per-index weights by name
756 $this->_indexweights = $weights;
760 /// only match records if document ID is beetwen $min and $max (inclusive)
761 function SetIDRange($min, $max) argument
764 assert(is_numeric($max));
765 assert($min <= $max);
766 $this->_min_id = $min;
767 $this->_max_id = $max;
782 …$this->_filters[] = array("type" => SPH_FILTER_VALUES, "attr" => $attribute, "exclude" => $exclude…
787 /// only match records if $attribute value is beetwen $min and $max (inclusive)
788 function SetFilterRange($attribute, $min, $max, $exclude = false) argument
792 assert(is_numeric($max));
793 assert($min <= $max);
795 …$this->_filters[] = array("type" => SPH_FILTER_RANGE, "attr" => $attribute, "exclude" => $exclude,…
799 /// only match records if $attribute value is beetwen $min and $max (inclusive)
800 function SetFilterFloatRange($attribute, $min, $max, $exclude = false) argument
804 assert(is_float($max));
805 assert($min <= $max);
807 …$this->_filters[] = array("type" => SPH_FILTER_FLOATRANGE, "attr" => $attribute, "exclude" => $exc…
820 …$this->_anchor = array("attrlat" => $attrlat, "attrlong" => $attrlong, "lat" => $lat, "long" => $l…
835 $this->_groupby = $attribute;
836 $this->_groupfunc = $func;
837 $this->_groupsort = $groupsort;
840 /// set count-distinct attribute for group-by queries
844 $this->_groupdistinct = $attribute;
852 $this->_retrycount = $count;
853 $this->_retrydelay = $delay;
857 /// PHP specific; needed for group-by-MVA result sets that may contain duplicate IDs
861 $this->_arrayresult = $arrayresult;
873 …$this->_overrides[$attrname] = array("attr" => $attrname, "type" => $attrtype, "values" => $values…
876 /// set select-list (attributes or expressions), SQL-like syntax
880 $this->_select = $select;
885 /// clear all filters (for multi-queries)
888 $this->_filters = array();
889 $this->_anchor = array();
892 /// clear groupby settings (for multi-queries)
895 $this->_groupby = "";
896 $this->_groupfunc = SPH_GROUPBY_DAY;
897 $this->_groupsort = "@group desc";
898 $this->_groupdistinct = "";
901 /// clear all attribute value overrides (for multi-queries)
904 $this->_overrides = array();
913 assert(empty($this->_reqs));
915 $this->AddQuery($query, $index, $comment);
916 $results = $this->RunQueries();
917 $this->_reqs = array(); // just in case it failed too early
922 $this->_error = $results[0]["error"];
923 $this->_warning = $results[0]["warning"];
934 list(, $t2) = unpack("L*", $t1); // int in machine order
938 /// add query to multi-query batch
943 $this->_MBPush();
946 …$req = pack("NNNNN", $this->_offset, $this->_limit, $this->_mode, $this->_ranker, $this->_sort); /…
947 $req .= pack("N", strlen($this->_sortby)) . $this->_sortby;
949 $req .= pack("N", count($this->_weights)); // weights
950 foreach ($this->_weights as $weight)
954 $req .= sphPackU64($this->_min_id) . sphPackU64($this->_max_id); // id64 range
957 $req .= pack("N", count($this->_filters));
958 foreach ($this->_filters as $filter) {
969 $req .= sphPackI64($filter["min"]) . sphPackI64($filter["max"]);
973 $req .= $this->_PackFloat($filter["min"]) . $this->_PackFloat($filter["max"]);
982 // group-by clause, max-matches count, group-sort clause, cutoff count
983 $req .= pack("NN", $this->_groupfunc, strlen($this->_groupby)) . $this->_groupby;
984 $req .= pack("N", $this->_maxmatches);
985 $req .= pack("N", strlen($this->_groupsort)) . $this->_groupsort;
986 $req .= pack("NNN", $this->_cutoff, $this->_retrycount, $this->_retrydelay);
987 $req .= pack("N", strlen($this->_groupdistinct)) . $this->_groupdistinct;
990 if (empty($this->_anchor)) {
993 $a = &$this->_anchor;
997 $req .= $this->_PackFloat($a["lat"]) . $this->_PackFloat($a["long"]);
1000 // per-index weights
1001 $req .= pack("N", count($this->_indexweights));
1002 foreach ($this->_indexweights as $idx => $weight)
1005 // max query time
1006 $req .= pack("N", $this->_maxquerytime);
1008 // per-field weights
1009 $req .= pack("N", count($this->_fieldweights));
1010 foreach ($this->_fieldweights as $field => $weight)
1017 $req .= pack("N", count($this->_overrides));
1018 foreach ($this->_overrides as $key => $entry) {
1028 $req .= $this->_PackFloat($val);
1040 // select-list
1041 $req .= pack("N", strlen($this->_select)) . $this->_select;
1044 $this->_MBPop();
1047 $this->_reqs[] = $req;
1048 return count($this->_reqs) - 1;
1054 if (empty($this->_reqs)) {
1055 $this->_error = "no queries defined, issue AddQuery() first";
1060 $this->_MBPush();
1062 if (!($fp = $this->_Connect())) {
1063 $this->_MBPop();
1068 $nreqs = count($this->_reqs);
1069 $req = join("", $this->_reqs);
1074 !($this->_Send($fp, $req, $len + 8)) ||
1075 !($response = $this->_GetResponse($fp, VER_COMMAND_SEARCH))
1077 $this->_MBPop();
1082 $this->_reqs = array();
1085 return $this->_ParseSearchResponse($response, $nreqs);
1092 $max = strlen($response); // max position for checks, to protect against broken responses
1095 for ($ires = 0; $ires < $nreqs && $p < $max; $ires++) {
1126 while ($nfields-- > 0 && $p < $max) {
1136 while ($nattrs-- > 0 && $p < $max) {
1154 $idx = -1;
1155 while ($count-- > 0 && $p < $max) {
1176 if ($this->_arrayresult)
1195 list(, $fval) = unpack("f*", pack("L", $uval));
1206 while ($nvalues-- > 0 && $p < $max) {
1216 if ($this->_arrayresult)
1229 while ($words-- > 0 && $p < $max) {
1243 $this->_MBPop();
1261 $this->_MBPush();
1263 if (!($fp = $this->_Connect())) {
1264 $this->_MBPop();
1317 !($this->_Send($fp, $req, $len + 8)) ||
1318 !($response = $this->_GetResponse($fp, VER_COMMAND_EXCERPT))
1320 $this->_MBPop();
1336 $this->_error = "incomplete reply";
1337 $this->_MBPop();
1344 $this->_MBPop();
1362 $this->_MBPush();
1364 if (!($fp = $this->_Connect())) {
1365 $this->_MBPop();
1385 !($this->_Send($fp, $req, $len + 8)) ||
1386 !($response = $this->_GetResponse($fp, VER_COMMAND_KEYWORDS))
1388 $this->_MBPop();
1422 $this->_error = "incomplete reply";
1423 $this->_MBPop();
1428 $this->_MBPop();
1434 $from = array('\\', '(', ')', '|', '-', '!', '@', '~', '"', '&', '/', '^', '$', '=');
1435 …$to = array('\\\\', '\(', '\)', '\|', '\-', '\!', '\@', '\~', '\"', '\&', '\/', '\^', '\$', '\='…
1445 /// returns amount of updated documents (0 or more) on success, or -1 on failure
1492 if (!($fp = $this->_Connect()))
1493 return -1;
1497 if (!$this->_Send($fp, $req, $len + 8))
1498 return -1;
1500 if (!($response = $this->_GetResponse($fp, VER_COMMAND_UPDATE)))
1501 return -1;
1514 if ($this->_socket !== false) {
1515 $this->_error = 'already connected';
1518 if (!$fp = $this->_Connect())
1523 if (!$this->_Send($fp, $req, 12))
1526 $this->_socket = $fp;
1532 if ($this->_socket === false) {
1533 $this->_error = 'not connected';
1537 fclose($this->_socket);
1538 $this->_socket = false;
1549 $this->_MBPush();
1550 if (!($fp = $this->_Connect())) {
1551 $this->_MBPop();
1557 !($this->_Send($fp, $req, 12)) ||
1558 !($response = $this->_GetResponse($fp, VER_COMMAND_STATUS))
1560 $this->_MBPop();
1578 $this->_MBPop();
1585 // $Id: sphinxapi.php 2055 2009-11-06 23:09:58Z shodan $