Обновление sphinxapi до версии 4522.
This commit is contained in:
Exile 2014-08-02 00:03:02 +04:00
commit a4c4d7fb48
2 changed files with 1857 additions and 1652 deletions

View file

@ -2516,7 +2516,7 @@ function init_sphinx ()
$sphinx->SetConnectTimeout(5);
# $sphinx->SetMaxQueryTime(2);
$sphinx->SetRankingMode(SPH_RANK_NONE);
$sphinx->SetMatchMode(SPH_MATCH_BOOLEAN);
# $sphinx->SetMatchMode(SPH_MATCH_BOOLEAN);
# $sphinx->SetSortMode($mode, $sortby="");
}
}

View file

@ -1,11 +1,13 @@
<?php
//
// $Id: sphinxapi.php 2055 2009-11-06 23:09:58Z shodan $
// $Id: sphinxapi.php 4522 2014-01-30 11:00:18Z tomat $
//
//
// Copyright (c) 2001-2008, Andrew Aksyonoff. All rights reserved.
// Copyright (c) 2001-2014, Andrew Aksyonoff
// Copyright (c) 2008-2014, Sphinx Technologies Inc
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License. You should have
@ -13,26 +15,32 @@
// did not, you can find it at http://www.gnu.org/
//
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// WARNING
// We strongly recommend you to use SphinxQL instead of the API
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/////////////////////////////////////////////////////////////////////////////
// PHP version of Sphinx searchd client (PHP API)
/////////////////////////////////////////////////////////////////////////////
/// known searchd commands
define ( "SEARCHD_COMMAND_SEARCH", 0 );
define ( "SEARCHD_COMMAND_EXCERPT", 1 );
define ( "SEARCHD_COMMAND_UPDATE", 2 );
define ( "SEARCHD_COMMAND_KEYWORDS",3 );
define ( "SEARCHD_COMMAND_PERSIST", 4 );
define ( "SEARCHD_COMMAND_STATUS", 5 );
define ( "SEARCHD_COMMAND_QUERY", 6 );
define ( "SEARCHD_COMMAND_SEARCH", 0 );
define ( "SEARCHD_COMMAND_EXCERPT", 1 );
define ( "SEARCHD_COMMAND_UPDATE", 2 );
define ( "SEARCHD_COMMAND_KEYWORDS", 3 );
define ( "SEARCHD_COMMAND_PERSIST", 4 );
define ( "SEARCHD_COMMAND_STATUS", 5 );
define ( "SEARCHD_COMMAND_FLUSHATTRS", 7 );
/// current client-side command implementation versions
define ( "VER_COMMAND_SEARCH", 0x116 );
define ( "VER_COMMAND_EXCERPT", 0x100 );
define ( "VER_COMMAND_UPDATE", 0x102 );
define ( "VER_COMMAND_SEARCH", 0x11E );
define ( "VER_COMMAND_EXCERPT", 0x104 );
define ( "VER_COMMAND_UPDATE", 0x103 );
define ( "VER_COMMAND_KEYWORDS", 0x100 );
define ( "VER_COMMAND_STATUS", 0x100 );
define ( "VER_COMMAND_STATUS", 0x101 );
define ( "VER_COMMAND_QUERY", 0x100 );
define ( "VER_COMMAND_FLUSHATTRS", 0x100 );
/// known searchd status codes
define ( "SEARCHD_OK", 0 );
@ -57,6 +65,9 @@ define ( "SPH_RANK_WORDCOUNT", 3 ); ///< simple word-count weighting, rank is a
define ( "SPH_RANK_PROXIMITY", 4 );
define ( "SPH_RANK_MATCHANY", 5 );
define ( "SPH_RANK_FIELDMASK", 6 );
define ( "SPH_RANK_SPH04", 7 );
define ( "SPH_RANK_EXPR", 8 );
define ( "SPH_RANK_TOTAL", 9 );
/// known sort modes
define ( "SPH_SORT_RELEVANCE", 0 );
@ -70,6 +81,7 @@ define ( "SPH_SORT_EXPR", 5 );
define ( "SPH_FILTER_VALUES", 0 );
define ( "SPH_FILTER_RANGE", 1 );
define ( "SPH_FILTER_FLOATRANGE", 2 );
define ( "SPH_FILTER_STRING", 3 );
/// known attribute types
define ( "SPH_ATTR_INTEGER", 1 );
@ -78,7 +90,10 @@ define ( "SPH_ATTR_ORDINAL", 3 );
define ( "SPH_ATTR_BOOL", 4 );
define ( "SPH_ATTR_FLOAT", 5 );
define ( "SPH_ATTR_BIGINT", 6 );
define ( "SPH_ATTR_MULTI", 0x40000000 );
define ( "SPH_ATTR_STRING", 7 );
define ( "SPH_ATTR_FACTORS", 1001 );
define ( "SPH_ATTR_MULTI", 0x40000001 );
define ( "SPH_ATTR_MULTI64", 0x40000002 );
/// known grouping functions
define ( "SPH_GROUPBY_DAY", 0 );
@ -373,6 +388,19 @@ function sphFixUint ( $value )
}
}
function sphSetBit ( $flag, $bit, $on )
{
if ( $on )
{
$flag += ( 1<<$bit );
} else
{
$reset = 255 ^ ( 1<<$bit );
$flag = $flag & $reset;
}
return $flag;
}
/// sphinx searchd client class
class SphinxClient extends cache_common
@ -381,7 +409,7 @@ class SphinxClient extends cache_common
var $_port; ///< searchd port (default is 9312)
var $_offset; ///< how many records to seek from result-set start (default is 0)
var $_limit; ///< how many records to return from result-set starting at offset (default is 20)
var $_mode; ///< query matching mode (default is SPH_MATCH_ALL)
var $_mode; ///< query matching mode (default is SPH_MATCH_EXTENDED2)
var $_weights; ///< per-field weights (default is 1 for all fields)
var $_sort; ///< match sorting mode (default is SPH_SORT_RELEVANCE)
var $_sortby; ///< attribute to sort by (defualt is "")
@ -399,10 +427,17 @@ class SphinxClient extends cache_common
var $_anchor; ///< geographical anchor point
var $_indexweights; ///< per-index weights
var $_ranker; ///< ranking mode (default is SPH_RANK_PROXIMITY_BM25)
var $_rankexpr; ///< ranking mode expression (for SPH_RANK_EXPR)
var $_maxquerytime; ///< max query time, milliseconds (default is 0, do not limit)
var $_fieldweights; ///< per-field-name weights
var $_overrides; ///< per-query attribute values overrides
var $_select; ///< select-list (attributes or expressions, with optional aliases)
var $_query_flags; ///< per-query various flags
var $_predictedtime; ///< per-query max_predicted_time
var $_outerorderby; ///< outer match sort by
var $_outeroffset; ///< outer offset
var $_outerlimit; ///< outer limit
var $_hasouter;
var $_error; ///< last error message
var $_warning; ///< last warning message
@ -434,7 +469,7 @@ class SphinxClient extends cache_common
// per-query settings
$this->_offset = 0;
$this->_limit = 2000;
$this->_mode = SPH_MATCH_ALL;
$this->_mode = SPH_MATCH_EXTENDED2;
$this->_weights = array ();
$this->_sort = SPH_SORT_RELEVANCE;
$this->_sortby = "";
@ -452,10 +487,17 @@ class SphinxClient extends cache_common
$this->_anchor = array ();
$this->_indexweights= array ();
$this->_ranker = SPH_RANK_PROXIMITY_BM25;
$this->_rankexpr = "";
$this->_maxquerytime= 0;
$this->_fieldweights= array();
$this->_overrides = array();
$this->_select = "*";
$this->_query_flags = sphSetBit ( 0, 6, true ); // default idf=tfidf_normalized
$this->_predictedtime = 0;
$this->_outerorderby = "";
$this->_outeroffset = 0;
$this->_outerlimit = 0;
$this->_hasouter = false;
$this->_error = ""; // per-reply fields (for single-query case)
$this->_warning = "";
@ -506,11 +548,11 @@ class SphinxClient extends cache_common
return;
}
assert ( is_int($port) );
$this->_host = $host;
$this->_port = $port;
$port = intval($port);
assert ( 0<=$port && $port<65536 );
$this->_port = ( $port==0 ) ? 9312 : $port;
$this->_path = '';
}
/// set server connection timeout (0 to remove)
@ -640,7 +682,7 @@ class SphinxClient extends cache_common
$left = $len;
while ( $left>0 && !feof($fp) )
{
$chunk = fread ( $fp, $left );
$chunk = fread ( $fp, min ( 8192, $left ) );
if ( $chunk )
{
$response .= $chunk;
@ -727,6 +769,7 @@ class SphinxClient extends cache_common
/// set matching mode
function SetMatchMode ( $mode )
{
trigger_error ( 'DEPRECATED: Do not call this method or, even better, use SphinxQL instead of an API', E_USER_DEPRECATED );
assert ( $mode==SPH_MATCH_ALL
|| $mode==SPH_MATCH_ANY
|| $mode==SPH_MATCH_PHRASE
@ -738,14 +781,12 @@ class SphinxClient extends cache_common
}
/// set ranking mode
function SetRankingMode ( $ranker )
function SetRankingMode ( $ranker, $rankexpr="" )
{
assert ( $ranker==SPH_RANK_PROXIMITY_BM25
|| $ranker==SPH_RANK_BM25
|| $ranker==SPH_RANK_NONE
|| $ranker==SPH_RANK_WORDCOUNT
|| $ranker==SPH_RANK_PROXIMITY );
assert ( $ranker===0 || $ranker>=1 && $ranker<SPH_RANK_TOTAL );
assert ( is_string($rankexpr) );
$this->_ranker = $ranker;
$this->_rankexpr = $rankexpr;
}
/// set matches sorting mode
@ -769,11 +810,7 @@ class SphinxClient extends cache_common
/// DEPRECATED; use SetFieldWeights() instead
function SetWeights ( $weights )
{
assert ( is_array($weights) );
foreach ( $weights as $weight )
assert ( is_int($weight) );
$this->_weights = $weights;
die("This method is now deprecated; please use SetFieldWeights instead");
}
/// bind per-field weights by name
@ -828,6 +865,15 @@ class SphinxClient extends cache_common
}
}
/// set string filter
/// only match records where $attribute value is equal
function SetFilterString ( $attribute, $value, $exclude=false )
{
assert ( is_string($attribute) );
assert ( is_string($value) );
$this->_filters[] = array ( "type"=>SPH_FILTER_STRING, "attr"=>$attribute, "exclude"=>$exclude, "value"=>$value );
}
/// set range filter
/// only match records if $attribute value is beetwen $min and $max (inclusive)
function SetFilterRange ( $attribute, $min, $max, $exclude=false )
@ -911,6 +957,7 @@ class SphinxClient extends cache_common
/// $values must be a hash that maps document IDs to attribute values
function SetOverride ( $attrname, $attrtype, $values )
{
trigger_error('DEPRECATED: Do not call this method. Use SphinxQL REMAP() function instead.', E_USER_DEPRECATED);
assert ( is_string ( $attrname ) );
assert ( in_array ( $attrtype, array ( SPH_ATTR_INTEGER, SPH_ATTR_TIMESTAMP, SPH_ATTR_BOOL, SPH_ATTR_FLOAT, SPH_ATTR_BIGINT ) ) );
assert ( is_array ( $values ) );
@ -925,6 +972,49 @@ class SphinxClient extends cache_common
$this->_select = $select;
}
function SetQueryFlag ( $flag_name, $flag_value )
{
$known_names = array ( "reverse_scan", "sort_method", "max_predicted_time", "boolean_simplify", "idf", "global_idf" );
$flags = array (
"reverse_scan" => array ( 0, 1 ),
"sort_method" => array ( "pq", "kbuffer" ),
"max_predicted_time" => array ( 0 ),
"boolean_simplify" => array ( true, false ),
"idf" => array ("normalized", "plain", "tfidf_normalized", "tfidf_unnormalized" ),
"global_idf" => array ( true, false ),
);
assert ( isset ( $flag_name, $known_names ) );
assert ( in_array( $flag_value, $flags[$flag_name], true ) || ( $flag_name=="max_predicted_time" && is_int ( $flag_value ) && $flag_value>=0 ) );
if ( $flag_name=="reverse_scan" ) $this->_query_flags = sphSetBit ( $this->_query_flags, 0, $flag_value==1 );
if ( $flag_name=="sort_method" ) $this->_query_flags = sphSetBit ( $this->_query_flags, 1, $flag_value=="kbuffer" );
if ( $flag_name=="max_predicted_time" )
{
$this->_query_flags = sphSetBit ( $this->_query_flags, 2, $flag_value>0 );
$this->_predictedtime = (int)$flag_value;
}
if ( $flag_name=="boolean_simplify" ) $this->_query_flags = sphSetBit ( $this->_query_flags, 3, $flag_value );
if ( $flag_name=="idf" && ( $flag_value=="normalized" || $flag_value=="plain" ) ) $this->_query_flags = sphSetBit ( $this->_query_flags, 4, $flag_value=="plain" );
if ( $flag_name=="global_idf" ) $this->_query_flags = sphSetBit ( $this->_query_flags, 5, $flag_value );
if ( $flag_name=="idf" && ( $flag_value=="tfidf_normalized" || $flag_value=="tfidf_unnormalized" ) ) $this->_query_flags = sphSetBit ( $this->_query_flags, 6, $flag_value=="tfidf_normalized" );
}
/// set outer order by parameters
function SetOuterSelect ( $orderby, $offset, $limit )
{
assert ( is_string($orderby) );
assert ( is_int($offset) );
assert ( is_int($limit) );
assert ( $offset>=0 );
assert ( $limit>0 );
$this->_outerorderby = $orderby;
$this->_outeroffset = $offset;
$this->_outerlimit = $limit;
$this->_hasouter = true;
}
//////////////////////////////////////////////////////////////////////////////
/// clear all filters (for multi-queries)
@ -949,6 +1039,20 @@ class SphinxClient extends cache_common
$this->_overrides = array ();
}
function ResetQueryFlag ()
{
$this->_query_flags = sphSetBit ( 0, 6, true ); // default idf=tfidf_normalized
$this->_predictedtime = 0;
}
function ResetOuterSelect ()
{
$this->_outerorderby = '';
$this->_outeroffset = 0;
$this->_outerlimit = 0;
$this->_hasouter = false;
}
//////////////////////////////////////////////////////////////////////////////
/// connect to searchd server, run given search query through given indexes,
@ -960,6 +1064,7 @@ class SphinxClient extends cache_common
$this->AddQuery ( $query, $index, $comment );
$results = $this->RunQueries ();
$this->_reqs = array (); // just in case it failed too early
$this->bb_queries = array();
$this->bb_indexes = array();
@ -990,7 +1095,10 @@ class SphinxClient extends cache_common
$this->_MBPush ();
// build request
$req = pack ( "NNNNN", $this->_offset, $this->_limit, $this->_mode, $this->_ranker, $this->_sort ); // mode and limits
$req = pack ( "NNNNN", $this->_query_flags, $this->_offset, $this->_limit, $this->_mode, $this->_ranker );
if ( $this->_ranker==SPH_RANK_EXPR )
$req .= pack ( "N", strlen($this->_rankexpr) ) . $this->_rankexpr;
$req .= pack ( "N", $this->_sort ); // (deprecated) sort mode
$req .= pack ( "N", strlen($this->_sortby) ) . $this->_sortby;
$req .= pack ( "N", strlen($query) ) . $query; // query itself
$req .= pack ( "N", count($this->_weights) ); // weights
@ -1022,6 +1130,10 @@ class SphinxClient extends cache_common
$req .= $this->_PackFloat ( $filter["min"] ) . $this->_PackFloat ( $filter["max"] );
break;
case SPH_FILTER_STRING:
$req .= pack ( "N", strlen($filter["value"]) ) . $filter["value"];
break;
default:
assert ( 0 && "internal error: unhandled filter type" );
}
@ -1088,6 +1200,17 @@ class SphinxClient extends cache_common
// select-list
$req .= pack ( "N", strlen($this->_select) ) . $this->_select;
// max_predicted_time
if ( $this->_predictedtime>0 )
$req .= pack ( "N", (int)$this->_predictedtime );
$req .= pack ( "N", strlen($this->_outerorderby) ) . $this->_outerorderby;
$req .= pack ( "NN", $this->_outeroffset, $this->_outerlimit );
if ( $this->_hasouter )
$req .= pack ( "N", 1 );
else
$req .= pack ( "N", 0 );
// mbstring workaround
$this->_MBPop ();
@ -1119,8 +1242,8 @@ class SphinxClient extends cache_common
// send query, get response
$nreqs = count($this->_reqs);
$req = join ( "", $this->_reqs );
$len = 4+strlen($req);
$req = pack ( "nnNN", SEARCHD_COMMAND_SEARCH, VER_COMMAND_SEARCH, $len, $nreqs ) . $req; // add header
$len = 8+strlen($req);
$req = pack ( "nnNNN", SEARCHD_COMMAND_SEARCH, VER_COMMAND_SEARCH, $len, 0, $nreqs ) . $req; // add header
$this->cur_query = 'query: `'. join ('` `', $this->bb_queries) .'` idx: `'. join ('` `', $this->bb_indexes) .'`';
$this->debug('start');
@ -1255,7 +1378,7 @@ class SphinxClient extends cache_common
// handle everything else as unsigned ints
list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4;
if ( $type & SPH_ATTR_MULTI )
if ( $type==SPH_ATTR_MULTI )
{
$attrvals[$attr] = array ();
$nvalues = $val;
@ -1264,6 +1387,23 @@ class SphinxClient extends cache_common
list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4;
$attrvals[$attr][] = sphFixUint($val);
}
} else if ( $type==SPH_ATTR_MULTI64 )
{
$attrvals[$attr] = array ();
$nvalues = $val;
while ( $nvalues>0 && $p<$max )
{
$attrvals[$attr][] = sphUnpackI64 ( substr ( $response, $p, 8 ) ); $p += 8;
$nvalues -= 2;
}
} else if ( $type==SPH_ATTR_STRING )
{
$attrvals[$attr] = substr ( $response, $p, $val );
$p += $val;
} else if ( $type==SPH_ATTR_FACTORS )
{
$attrvals[$attr] = substr ( $response, $p, $val-4 );
$p += $val-4;
} else
{
$attrvals[$attr] = sphFixUint($val);
@ -1330,22 +1470,39 @@ class SphinxClient extends cache_common
if ( !isset($opts["after_match"]) ) $opts["after_match"] = "</b>";
if ( !isset($opts["chunk_separator"]) ) $opts["chunk_separator"] = " ... ";
if ( !isset($opts["limit"]) ) $opts["limit"] = 256;
if ( !isset($opts["limit_passages"]) ) $opts["limit_passages"] = 0;
if ( !isset($opts["limit_words"]) ) $opts["limit_words"] = 0;
if ( !isset($opts["around"]) ) $opts["around"] = 5;
if ( !isset($opts["exact_phrase"]) ) $opts["exact_phrase"] = false;
if ( !isset($opts["single_passage"]) ) $opts["single_passage"] = false;
if ( !isset($opts["use_boundaries"]) ) $opts["use_boundaries"] = false;
if ( !isset($opts["weight_order"]) ) $opts["weight_order"] = false;
if ( !isset($opts["query_mode"]) ) $opts["query_mode"] = false;
if ( !isset($opts["force_all_words"]) ) $opts["force_all_words"] = false;
if ( !isset($opts["start_passage_id"]) ) $opts["start_passage_id"] = 1;
if ( !isset($opts["load_files"]) ) $opts["load_files"] = false;
if ( !isset($opts["html_strip_mode"]) ) $opts["html_strip_mode"] = "index";
if ( !isset($opts["allow_empty"]) ) $opts["allow_empty"] = false;
if ( !isset($opts["passage_boundary"]) ) $opts["passage_boundary"] = "none";
if ( !isset($opts["emit_zones"]) ) $opts["emit_zones"] = false;
if ( !isset($opts["load_files_scattered"]) ) $opts["load_files_scattered"] = false;
/////////////////
// build request
/////////////////
// v.1.0 req
// v.1.2 req
$flags = 1; // remove spaces
if ( $opts["exact_phrase"] ) $flags |= 2;
if ( $opts["single_passage"] ) $flags |= 4;
if ( $opts["use_boundaries"] ) $flags |= 8;
if ( $opts["weight_order"] ) $flags |= 16;
if ( $opts["query_mode"] ) $flags |= 32;
if ( $opts["force_all_words"] ) $flags |= 64;
if ( $opts["load_files"] ) $flags |= 128;
if ( $opts["allow_empty"] ) $flags |= 256;
if ( $opts["emit_zones"] ) $flags |= 512;
if ( $opts["load_files_scattered"] ) $flags |= 1024;
$req = pack ( "NN", 0, $flags ); // mode=0, flags=$flags
$req .= pack ( "N", strlen($index) ) . $index; // req index
$req .= pack ( "N", strlen($words) ) . $words; // req words
@ -1354,8 +1511,10 @@ class SphinxClient extends cache_common
$req .= pack ( "N", strlen($opts["before_match"]) ) . $opts["before_match"];
$req .= pack ( "N", strlen($opts["after_match"]) ) . $opts["after_match"];
$req .= pack ( "N", strlen($opts["chunk_separator"]) ) . $opts["chunk_separator"];
$req .= pack ( "N", (int)$opts["limit"] );
$req .= pack ( "N", (int)$opts["around"] );
$req .= pack ( "NN", (int)$opts["limit"], (int)$opts["around"] );
$req .= pack ( "NNN", (int)$opts["limit_passages"], (int)$opts["limit_words"], (int)$opts["start_passage_id"] ); // v.1.2
$req .= pack ( "N", strlen($opts["html_strip_mode"]) ) . $opts["html_strip_mode"];
$req .= pack ( "N", strlen($opts["passage_boundary"]) ) . $opts["passage_boundary"];
// documents
$req .= pack ( "N", count($docs) );
@ -1491,8 +1650,8 @@ class SphinxClient extends cache_common
function EscapeString ( $string )
{
$from = array ( '\\', '(',')','|','-','!','@','~','"','&', '/', '^', '$', '=' );
$to = array ( '\\\\', '\(','\)','\|','\-','\!','\@','\~','\"', '\&', '\/', '\^', '\$', '\=' );
$from = array ( '\\', '(',')','|','-','!','@','~','"','&', '/', '^', '$', '=', '<' );
$to = array ( '\\\\', '\(','\)','\|','\-','\!','\@','\~','\"', '\&', '\/', '\^', '\$', '\=', '\<' );
return str_replace ( $from, $to, $string );
}
@ -1503,11 +1662,12 @@ class SphinxClient extends cache_common
/// batch update given attributes in given rows in given indexes
/// returns amount of updated documents (0 or more) on success, or -1 on failure
function UpdateAttributes ( $index, $attrs, $values, $mva=false )
function UpdateAttributes ( $index, $attrs, $values, $mva=false, $ignorenonexistent=false )
{
// verify everything
assert ( is_string($index) );
assert ( is_bool($mva) );
assert ( is_bool($ignorenonexistent) );
assert ( is_array($attrs) );
foreach ( $attrs as $attr )
@ -1532,9 +1692,11 @@ class SphinxClient extends cache_common
}
// build request
$this->_MBPush ();
$req = pack ( "N", strlen($index) ) . $index;
$req .= pack ( "N", count($attrs) );
$req .= pack ( "N", $ignorenonexistent ? 1 : 0 );
foreach ( $attrs as $attr )
{
$req .= pack ( "N", strlen($attr) ) . $attr;
@ -1556,18 +1718,28 @@ class SphinxClient extends cache_common
// connect, send query, get response
if (!( $fp = $this->_Connect() ))
{
$this->_MBPop ();
return -1;
}
$len = strlen($req);
$req = pack ( "nnN", SEARCHD_COMMAND_UPDATE, VER_COMMAND_UPDATE, $len ) . $req; // add header
if ( !$this->_Send ( $fp, $req, $len+8 ) )
{
$this->_MBPop ();
return -1;
}
if (!( $response = $this->_GetResponse ( $fp, VER_COMMAND_UPDATE ) ))
{
$this->_MBPop ();
return -1;
}
// parse response
list(,$updated) = unpack ( "N*", substr ( $response, 0, 4 ) );
$this->_MBPop ();
return $updated;
}
@ -1612,8 +1784,10 @@ class SphinxClient extends cache_common
// status
//////////////////////////////////////////////////////////////////////////
function Status ()
function Status ($session=false)
{
assert ( is_bool($session) );
$this->_MBPush ();
if (!( $fp = $this->_Connect() ))
{
@ -1621,7 +1795,7 @@ class SphinxClient extends cache_common
return false;
}
$req = pack ( "nnNN", SEARCHD_COMMAND_STATUS, VER_COMMAND_STATUS, 4, 1 ); // len=4, body=1
$req = pack ( "nnNN", SEARCHD_COMMAND_STATUS, VER_COMMAND_STATUS, 4, $session?0:1 ); // len=4, body=1
if ( !( $this->_Send ( $fp, $req, 12 ) ) ||
!( $response = $this->_GetResponse ( $fp, VER_COMMAND_STATUS ) ) )
{
@ -1644,8 +1818,39 @@ class SphinxClient extends cache_common
$this->_MBPop ();
return $res;
}
//////////////////////////////////////////////////////////////////////////
// flush
//////////////////////////////////////////////////////////////////////////
function FlushAttributes ()
{
$this->_MBPush ();
if (!( $fp = $this->_Connect() ))
{
$this->_MBPop();
return -1;
}
$req = pack ( "nnN", SEARCHD_COMMAND_FLUSHATTRS, VER_COMMAND_FLUSHATTRS, 0 ); // len=0
if ( !( $this->_Send ( $fp, $req, 8 ) ) ||
!( $response = $this->_GetResponse ( $fp, VER_COMMAND_FLUSHATTRS ) ) )
{
$this->_MBPop ();
return -1;
}
$tag = -1;
if ( strlen($response)==4 )
list(,$tag) = unpack ( "N*", $response );
else
$this->_error = "unexpected response length";
$this->_MBPop ();
return $tag;
}
}
//
// $Id: sphinxapi.php 2055 2009-11-06 23:09:58Z shodan $
// $Id: sphinxapi.php 4522 2014-01-30 11:00:18Z tomat $
//