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 …efine ( "SPH_RANK_WORDCOUNT", 3 ); ///< simple word-count weighting, rank is a weighted sum of pe…
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
131 return pack ( "NN", $v < 0 ? -1 : 0, $v );
136 if ( bccomp ( $v, 0 ) == -1 )
139 $l = bcmod ( $v, "4294967296" );
140 …return pack ( "NN", (float)$h, (float)$l ); // conversion to float is intentional; int would lose …
143 // x32, no-bcmath
144 $p = max(0, strlen($v) - 13);
150 $l = $m - ($q*4294967296.0);
155 if ( $l==0 )
156 $h = 4294967296.0 - $h;
159 $h = 4294967295.0 - $h;
160 $l = 4294967296.0 - $l;
163 return pack ( "NN", $h, $l );
166 /// pack 64-bit unsigned
184 $l = bcmod ( $v, 4294967296 );
185 return pack ( "NN", $h, $l );
188 // x64, no-bcmath
189 $p = max ( 0, strlen($v) - 13 );
194 $l = $m % 4294967296;
197 return pack ( "NN", $h, $l );
208 $l = bcmod ( $v, "4294967296" );
209 …return pack ( "NN", (float)$h, (float)$l ); // conversion to float is intentional; int would lose …
212 // x32, no-bcmath
213 $p = max(0, strlen($v) - 13);
219 $l = $m - ($q * 4294967296.0);
222 return pack ( "NN", $h, $l );
225 // unpack 64-bit unsigned
243 // x64, no-bcmath
246 $l = (($hi % $C) << 32) + ($lo % $C);
247 if ( $l>$C )
249 $h += (int)($l / $C);
250 $l = $l % $C;
254 return $l;
255 return sprintf ( "%d%05d", $h, $l );
273 // x32, no-bcmath
278 $r = $hi - $q*10000000.0;
281 $l = $m - $mq*10000000.0;
285 $l = sprintf ( "%07.0f", $l );
287 return sprintf( "%.0f", (float)$l );
288 return $h . $l;
291 // unpack 64-bit signed
313 elseif ( $hi==-1 )
317 return sprintf ( "%.0f", $lo - 4294967296.0 );
327 $neg = "-";
337 // x32, no-bcmath
342 $r = $hi - $q*10000000.0;
345 $l = $m - $mq*10000000.0 + $c;
347 if ( $l==10000000 )
349 $l = 0;
354 $l = sprintf ( "%07.0f", $l );
356 return $neg . sprintf( "%.0f", (float)$l );
357 return $neg . $h . $l;
382 var $_offset; ///< how many records to seek from result-set start (default is 0)
383 var $_limit; ///< how many records to return from result-set starting at offset (default is 20)
385 var $_weights; ///< per-field weights (default is 1 for all fields)
389 var $_max_id; ///< max ID to match (default is 0, which means no limit)
391 var $_groupby; ///< group-by attribute name
392 var $_groupfunc; ///< group-by function (to pre-process group-by attribute value with)
393 var $_groupsort; ///< group-by sorting clause (to sort groups in result set with)
394 var $_groupdistinct;///< group-by count-distinct attribute
395 var $_maxmatches; ///< max matches to retrieve
400 var $_indexweights; ///< per-index weights
402 var $_maxquerytime; ///< max query time, milliseconds (default is 0, do not limit)
403 var $_fieldweights; ///< per-field-name weights
404 var $_overrides; ///< per-query attribute values overrides
405 var $_select; ///< select-list (attributes or expressions, with optional aliases)
411 var $_reqs; ///< requests array for multi-query
423 // per-client-object settings
424 $this->_host = "localhost";
425 $this->_port = 9312;
426 $this->_path = false;
427 $this->_socket = false;
429 // per-query settings
430 $this->_offset = 0;
431 $this->_limit = 20;
432 $this->_mode = SPH_MATCH_ALL;
433 $this->_weights = array ();
434 $this->_sort = SPH_SORT_RELEVANCE;
435 $this->_sortby = "";
436 $this->_min_id = 0;
437 $this->_max_id = 0;
438 $this->_filters = array ();
439 $this->_groupby = "";
440 $this->_groupfunc = SPH_GROUPBY_DAY;
441 $this->_groupsort = "@group desc";
442 $this->_groupdistinct= "";
443 $this->_maxmatches = 1000;
444 $this->_cutoff = 0;
445 $this->_retrycount = 0;
446 $this->_retrydelay = 0;
447 $this->_anchor = array ();
448 $this->_indexweights= array ();
449 $this->_ranker = SPH_RANK_PROXIMITY_BM25;
450 $this->_maxquerytime= 0;
451 $this->_fieldweights= array();
452 $this->_overrides = array();
453 $this->_select = "*";
455 $this->_error = ""; // per-reply fields (for single-query case)
456 $this->_warning = "";
457 $this->_connerror = false;
459 $this->_reqs = array (); // requests storage (for multi-query case)
460 $this->_mbenc = "";
461 $this->_arrayresult = false;
462 $this->_timeout = 0;
467 if ( $this->_socket !== false )
468 fclose ( $this->_socket );
474 return $this->_error;
480 return $this->_warning;
486 return $this->_connerror;
495 $this->_path = 'unix://' . $host;
500 $this->_path = $host;
505 $this->_host = $host;
506 $this->_port = $port;
507 $this->_path = '';
515 $this->_timeout = $timeout;
523 $this->_error = 'connection unexpectedly closed (timed out?)';
524 $this->_connerror = true;
535 $this->_mbenc = "";
538 $this->_mbenc = mb_internal_encoding();
546 if ( $this->_mbenc )
547 mb_internal_encoding ( $this->_mbenc );
553 if ( $this->_socket!==false )
557 if ( !@feof ( $this->_socket ) )
558 return $this->_socket;
561 $this->_socket = false;
566 $this->_connerror = false;
568 if ( $this->_path )
570 $host = $this->_path;
575 $host = $this->_host;
576 $port = $this->_port;
579 if ( $this->_timeout<=0 )
582 $fp = @fsockopen ( $host, $port, $errno, $errstr, $this->_timeout );
586 if ( $this->_path )
587 $location = $this->_path;
589 $location = "{$this->_host}:{$this->_port}";
592 $this->_error = "connection to $location failed (errno=$errno, msg=$errstr)";
593 $this->_connerror = true;
600 // TCP stack could throttle write-write-read pattern because of Nagle.
601 if ( !$this->_Send ( $fp, pack ( "N", 1 ), 4 ) )
604 $this->_error = "failed to send client protocol version";
614 $this->_error = "expected searchd protocol version 1+, got version '$v'";
638 $left -= strlen($chunk);
642 if ( $this->_socket === false )
649 $this->_error = $len
651 : "received zero-sized searchd response";
659 $this->_warning = substr ( $response, 4, $wlen );
664 $this->_error = "searchd error: " . substr ( $response, 4 );
669 $this->_error = "temporary searchd error: " . substr ( $response, 4 );
674 $this->_error = "unknown status code '$status'";
681 …$this->_warning = sprintf ( "searchd command v.%d.%d older than client's v.%d.%d, some options mig…
693 /// and optionally set max-matches and cutoff limits
694 function SetLimits ( $offset, $limit, $max=0, $cutoff=0 ) argument
700 assert ( $max>=0 );
701 $this->_offset = $offset;
702 $this->_limit = $limit;
703 if ( $max>0 )
704 $this->_maxmatches = $max;
706 $this->_cutoff = $cutoff;
709 /// set maximum query time, in milliseconds, per-index
711 function SetMaxQueryTime ( $max ) argument
713 assert ( is_int($max) );
714 assert ( $max>=0 );
715 $this->_maxquerytime = $max;
728 $this->_mode = $mode;
739 $this->_ranker = $ranker;
755 $this->_sort = $mode;
756 $this->_sortby = $sortby;
759 /// bind per-field weights by order
767 $this->_weights = $weights;
770 /// bind per-field weights by name
779 $this->_fieldweights = $weights;
782 /// bind per-index weights by name
791 $this->_indexweights = $weights;
795 /// only match records if document ID is beetwen $min and $max (inclusive)
796 function SetIDRange ( $min, $max ) argument
799 assert ( is_numeric($max) );
800 assert ( $min<=$max );
801 $this->_min_id = $min;
802 $this->_max_id = $max;
818 …$this->_filters[] = array ( "type"=>SPH_FILTER_VALUES, "attr"=>$attribute, "exclude"=>$exclude, "v…
823 /// only match records if $attribute value is beetwen $min and $max (inclusive)
824 function SetFilterRange ( $attribute, $min, $max, $exclude=false ) argument
828 assert ( is_numeric($max) );
829 assert ( $min<=$max );
831 …$this->_filters[] = array ( "type"=>SPH_FILTER_RANGE, "attr"=>$attribute, "exclude"=>$exclude, "mi…
835 /// only match records if $attribute value is beetwen $min and $max (inclusive)
836 function SetFilterFloatRange ( $attribute, $min, $max, $exclude=false ) argument
840 assert ( is_float($max) );
841 assert ( $min<=$max );
843 …$this->_filters[] = array ( "type"=>SPH_FILTER_FLOATRANGE, "attr"=>$attribute, "exclude"=>$exclude…
856 $this->_anchor = array ( "attrlat"=>$attrlat, "attrlong"=>$attrlong, "lat"=>$lat, "long"=>$long );
871 $this->_groupby = $attribute;
872 $this->_groupfunc = $func;
873 $this->_groupsort = $groupsort;
876 /// set count-distinct attribute for group-by queries
880 $this->_groupdistinct = $attribute;
888 $this->_retrycount = $count;
889 $this->_retrydelay = $delay;
893 /// PHP specific; needed for group-by-MVA result sets that may contain duplicate IDs
897 $this->_arrayresult = $arrayresult;
909 $this->_overrides[$attrname] = array ( "attr"=>$attrname, "type"=>$attrtype, "values"=>$values );
912 /// set select-list (attributes or expressions), SQL-like syntax
916 $this->_select = $select;
921 /// clear all filters (for multi-queries)
924 $this->_filters = array();
925 $this->_anchor = array();
928 /// clear groupby settings (for multi-queries)
931 $this->_groupby = "";
932 $this->_groupfunc = SPH_GROUPBY_DAY;
933 $this->_groupsort = "@group desc";
934 $this->_groupdistinct= "";
937 /// clear all attribute value overrides (for multi-queries)
940 $this->_overrides = array ();
949 assert ( empty($this->_reqs) );
951 $this->AddQuery ( $query, $index, $comment );
952 $results = $this->RunQueries ();
953 $this->_reqs = array (); // just in case it failed too early
958 $this->_error = $results[0]["error"];
959 $this->_warning = $results[0]["warning"];
970 list(,$t2) = unpack ( "L*", $t1 ); // int in machine order
974 /// add query to multi-query batch
979 $this->_MBPush ();
982 …$req = pack ( "NNNNN", $this->_offset, $this->_limit, $this->_mode, $this->_ranker, $this->_sort )…
983 $req .= pack ( "N", strlen($this->_sortby) ) . $this->_sortby;
985 $req .= pack ( "N", count($this->_weights) ); // weights
986 foreach ( $this->_weights as $weight )
990 $req .= sphPackU64 ( $this->_min_id ) . sphPackU64 ( $this->_max_id ); // id64 range
993 $req .= pack ( "N", count($this->_filters) );
994 foreach ( $this->_filters as $filter )
1007 $req .= sphPackI64 ( $filter["min"] ) . sphPackI64 ( $filter["max"] );
1011 $req .= $this->_PackFloat ( $filter["min"] ) . $this->_PackFloat ( $filter["max"] );
1020 // group-by clause, max-matches count, group-sort clause, cutoff count
1021 $req .= pack ( "NN", $this->_groupfunc, strlen($this->_groupby) ) . $this->_groupby;
1022 $req .= pack ( "N", $this->_maxmatches );
1023 $req .= pack ( "N", strlen($this->_groupsort) ) . $this->_groupsort;
1024 $req .= pack ( "NNN", $this->_cutoff, $this->_retrycount, $this->_retrydelay );
1025 $req .= pack ( "N", strlen($this->_groupdistinct) ) . $this->_groupdistinct;
1028 if ( empty($this->_anchor) )
1033 $a =& $this->_anchor;
1037 $req .= $this->_PackFloat ( $a["lat"] ) . $this->_PackFloat ( $a["long"] );
1040 // per-index weights
1041 $req .= pack ( "N", count($this->_indexweights) );
1042 foreach ( $this->_indexweights as $idx=>$weight )
1045 // max query time
1046 $req .= pack ( "N", $this->_maxquerytime );
1048 // per-field weights
1049 $req .= pack ( "N", count($this->_fieldweights) );
1050 foreach ( $this->_fieldweights as $field=>$weight )
1057 $req .= pack ( "N", count($this->_overrides) );
1058 foreach ( $this->_overrides as $key => $entry )
1070 case SPH_ATTR_FLOAT: $req .= $this->_PackFloat ( $val ); break;
1077 // select-list
1078 $req .= pack ( "N", strlen($this->_select) ) . $this->_select;
1081 $this->_MBPop ();
1084 $this->_reqs[] = $req;
1085 return count($this->_reqs)-1;
1091 if ( empty($this->_reqs) )
1093 $this->_error = "no queries defined, issue AddQuery() first";
1098 $this->_MBPush ();
1100 if (!( $fp = $this->_Connect() ))
1102 $this->_MBPop ();
1107 $nreqs = count($this->_reqs);
1108 $req = join ( "", $this->_reqs );
1112 if ( !( $this->_Send ( $fp, $req, $len+8 ) ) ||
1113 !( $response = $this->_GetResponse ( $fp, VER_COMMAND_SEARCH ) ) )
1115 $this->_MBPop ();
1120 $this->_reqs = array ();
1123 return $this->_ParseSearchResponse ( $response, $nreqs );
1130 $max = strlen($response); // max position for checks, to protect against broken responses
1133 for ( $ires=0; $ires<$nreqs && $p<$max; $ires++ )
1164 while ( $nfields-->0 && $p<$max )
1172 while ( $nattrs-->0 && $p<$max )
1186 $idx = -1;
1187 while ( $count-->0 && $p<$max )
1208 if ( $this->_arrayresult )
1228 list(,$fval) = unpack ( "f*", pack ( "L", $uval ) );
1239 while ( $nvalues-->0 && $p<$max )
1250 if ( $this->_arrayresult )
1263 while ( $words-->0 && $p<$max )
1274 $this->_MBPop ();
1292 $this->_MBPush ();
1294 if (!( $fp = $this->_Connect() ))
1296 $this->_MBPop();
1349 if ( !( $this->_Send ( $fp, $req, $len+8 ) ) ||
1350 !( $response = $this->_GetResponse ( $fp, VER_COMMAND_EXCERPT ) ) )
1352 $this->_MBPop ();
1370 $this->_error = "incomplete reply";
1371 $this->_MBPop ();
1378 $this->_MBPop ();
1396 $this->_MBPush ();
1398 if (!( $fp = $this->_Connect() ))
1400 $this->_MBPop();
1419 if ( !( $this->_Send ( $fp, $req, $len+8 ) ) ||
1420 !( $response = $this->_GetResponse ( $fp, VER_COMMAND_KEYWORDS ) ) )
1422 $this->_MBPop ();
1457 $this->_error = "incomplete reply";
1458 $this->_MBPop ();
1463 $this->_MBPop ();
1469 $from = array ( '\\', '(',')','|','-','!','@','~','"','&', '/', '^', '$', '=' );
1470 $to = array ( '\\\\', '\(','\)','\|','\-','\!','\@','\~','\"', '\&', '\/', '\^', '\$', '\=' );
1480 /// returns amount of updated documents (0 or more) on success, or -1 on failure
1533 if (!( $fp = $this->_Connect() ))
1534 return -1;
1538 if ( !$this->_Send ( $fp, $req, $len+8 ) )
1539 return -1;
1541 if (!( $response = $this->_GetResponse ( $fp, VER_COMMAND_UPDATE ) ))
1542 return -1;
1555 if ( $this->_socket !== false )
1557 $this->_error = 'already connected';
1560 if ( !$fp = $this->_Connect() )
1565 if ( !$this->_Send ( $fp, $req, 12 ) )
1568 $this->_socket = $fp;
1574 if ( $this->_socket === false )
1576 $this->_error = 'not connected';
1580 fclose ( $this->_socket );
1581 $this->_socket = false;
1592 $this->_MBPush ();
1593 if (!( $fp = $this->_Connect() ))
1595 $this->_MBPop();
1600 if ( !( $this->_Send ( $fp, $req, 12 ) ) ||
1601 !( $response = $this->_GetResponse ( $fp, VER_COMMAND_STATUS ) ) )
1603 $this->_MBPop ();
1619 $this->_MBPop ();
1627 // $Id: sphinxapi.php 2055 2009-11-06 23:09:58Z shodan $