Skip to content

Commit 19cde79

Browse files
committed
Update to version 1.10
1 parent 5d2f54a commit 19cde79

File tree

1 file changed

+82
-20
lines changed

1 file changed

+82
-20
lines changed

sphinxapi.php

+82-20
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
22

33
//
4-
// $Id: sphinxapi.php 2055 2009-11-06 23:09:58Z shodan $
4+
// $Id: sphinxapi.php 2376 2010-06-29 14:08:19Z shodan $
55
//
66

77
//
8-
// Copyright (c) 2001-2008, Andrew Aksyonoff. All rights reserved.
8+
// Copyright (c) 2001-2010, Andrew Aksyonoff
9+
// Copyright (c) 2008-2010, Sphinx Technologies Inc
10+
// All rights reserved
911
//
1012
// This program is free software; you can redistribute it and/or modify
1113
// it under the terms of the GNU General Public License. You should have
@@ -18,21 +20,23 @@
1820
/////////////////////////////////////////////////////////////////////////////
1921

2022
/// known searchd commands
21-
define ( "SEARCHD_COMMAND_SEARCH", 0 );
22-
define ( "SEARCHD_COMMAND_EXCERPT", 1 );
23-
define ( "SEARCHD_COMMAND_UPDATE", 2 );
24-
define ( "SEARCHD_COMMAND_KEYWORDS",3 );
25-
define ( "SEARCHD_COMMAND_PERSIST", 4 );
26-
define ( "SEARCHD_COMMAND_STATUS", 5 );
27-
define ( "SEARCHD_COMMAND_QUERY", 6 );
23+
define ( "SEARCHD_COMMAND_SEARCH", 0 );
24+
define ( "SEARCHD_COMMAND_EXCERPT", 1 );
25+
define ( "SEARCHD_COMMAND_UPDATE", 2 );
26+
define ( "SEARCHD_COMMAND_KEYWORDS", 3 );
27+
define ( "SEARCHD_COMMAND_PERSIST", 4 );
28+
define ( "SEARCHD_COMMAND_STATUS", 5 );
29+
define ( "SEARCHD_COMMAND_QUERY", 6 );
30+
define ( "SEARCHD_COMMAND_FLUSHATTRS", 7 );
2831

2932
/// current client-side command implementation versions
30-
define ( "VER_COMMAND_SEARCH", 0x116 );
31-
define ( "VER_COMMAND_EXCERPT", 0x100 );
33+
define ( "VER_COMMAND_SEARCH", 0x117 );
34+
define ( "VER_COMMAND_EXCERPT", 0x102 );
3235
define ( "VER_COMMAND_UPDATE", 0x102 );
3336
define ( "VER_COMMAND_KEYWORDS", 0x100 );
3437
define ( "VER_COMMAND_STATUS", 0x100 );
3538
define ( "VER_COMMAND_QUERY", 0x100 );
39+
define ( "VER_COMMAND_FLUSHATTRS", 0x100 );
3640

3741
/// known searchd status codes
3842
define ( "SEARCHD_OK", 0 );
@@ -57,6 +61,8 @@
5761
define ( "SPH_RANK_PROXIMITY", 4 );
5862
define ( "SPH_RANK_MATCHANY", 5 );
5963
define ( "SPH_RANK_FIELDMASK", 6 );
64+
define ( "SPH_RANK_SPH04", 7 );
65+
define ( "SPH_RANK_TOTAL", 8 );
6066

6167
/// known sort modes
6268
define ( "SPH_SORT_RELEVANCE", 0 );
@@ -78,6 +84,7 @@
7884
define ( "SPH_ATTR_BOOL", 4 );
7985
define ( "SPH_ATTR_FLOAT", 5 );
8086
define ( "SPH_ATTR_BIGINT", 6 );
87+
define ( "SPH_ATTR_STRING", 7 );
8188
define ( "SPH_ATTR_MULTI", 0x40000000 );
8289

8390
/// known grouping functions
@@ -731,11 +738,7 @@ function SetMatchMode ( $mode )
731738
/// set ranking mode
732739
function SetRankingMode ( $ranker )
733740
{
734-
assert ( $ranker==SPH_RANK_PROXIMITY_BM25
735-
|| $ranker==SPH_RANK_BM25
736-
|| $ranker==SPH_RANK_NONE
737-
|| $ranker==SPH_RANK_WORDCOUNT
738-
|| $ranker==SPH_RANK_PROXIMITY );
741+
assert ( $ranker>=0 && $ranker<SPH_RANK_TOTAL );
739742
$this->_ranker = $ranker;
740743
}
741744

@@ -1241,6 +1244,10 @@ function _ParseSearchResponse ( $response, $nreqs )
12411244
list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4;
12421245
$attrvals[$attr][] = sphFixUint($val);
12431246
}
1247+
} else if ( $type==SPH_ATTR_STRING )
1248+
{
1249+
$attrvals[$attr] = substr ( $response, $p, $val );
1250+
$p += $val;
12441251
} else
12451252
{
12461253
$attrvals[$attr] = sphFixUint($val);
@@ -1305,22 +1312,34 @@ function BuildExcerpts ( $docs, $index, $words, $opts=array() )
13051312
if ( !isset($opts["after_match"]) ) $opts["after_match"] = "</b>";
13061313
if ( !isset($opts["chunk_separator"]) ) $opts["chunk_separator"] = " ... ";
13071314
if ( !isset($opts["limit"]) ) $opts["limit"] = 256;
1315+
if ( !isset($opts["limit_passages"]) ) $opts["limit_passages"] = 0;
1316+
if ( !isset($opts["limit_words"]) ) $opts["limit_words"] = 0;
13081317
if ( !isset($opts["around"]) ) $opts["around"] = 5;
13091318
if ( !isset($opts["exact_phrase"]) ) $opts["exact_phrase"] = false;
13101319
if ( !isset($opts["single_passage"]) ) $opts["single_passage"] = false;
13111320
if ( !isset($opts["use_boundaries"]) ) $opts["use_boundaries"] = false;
13121321
if ( !isset($opts["weight_order"]) ) $opts["weight_order"] = false;
1322+
if ( !isset($opts["query_mode"]) ) $opts["query_mode"] = false;
1323+
if ( !isset($opts["force_all_words"]) ) $opts["force_all_words"] = false;
1324+
if ( !isset($opts["start_passage_id"]) ) $opts["start_passage_id"] = 1;
1325+
if ( !isset($opts["load_files"]) ) $opts["load_files"] = false;
1326+
if ( !isset($opts["html_strip_mode"]) ) $opts["html_strip_mode"] = "index";
1327+
if ( !isset($opts["allow_empty"]) ) $opts["allow_empty"] = false;
13131328

13141329
/////////////////
13151330
// build request
13161331
/////////////////
13171332

1318-
// v.1.0 req
1333+
// v.1.2 req
13191334
$flags = 1; // remove spaces
13201335
if ( $opts["exact_phrase"] ) $flags |= 2;
13211336
if ( $opts["single_passage"] ) $flags |= 4;
13221337
if ( $opts["use_boundaries"] ) $flags |= 8;
13231338
if ( $opts["weight_order"] ) $flags |= 16;
1339+
if ( $opts["query_mode"] ) $flags |= 32;
1340+
if ( $opts["force_all_words"] ) $flags |= 64;
1341+
if ( $opts["load_files"] ) $flags |= 128;
1342+
if ( $opts["allow_empty"] ) $flags |= 256;
13241343
$req = pack ( "NN", 0, $flags ); // mode=0, flags=$flags
13251344
$req .= pack ( "N", strlen($index) ) . $index; // req index
13261345
$req .= pack ( "N", strlen($words) ) . $words; // req words
@@ -1329,8 +1348,9 @@ function BuildExcerpts ( $docs, $index, $words, $opts=array() )
13291348
$req .= pack ( "N", strlen($opts["before_match"]) ) . $opts["before_match"];
13301349
$req .= pack ( "N", strlen($opts["after_match"]) ) . $opts["after_match"];
13311350
$req .= pack ( "N", strlen($opts["chunk_separator"]) ) . $opts["chunk_separator"];
1332-
$req .= pack ( "N", (int)$opts["limit"] );
1333-
$req .= pack ( "N", (int)$opts["around"] );
1351+
$req .= pack ( "NN", (int)$opts["limit"], (int)$opts["around"] );
1352+
$req .= pack ( "NNN", (int)$opts["limit_passages"], (int)$opts["limit_words"], (int)$opts["start_passage_id"] ); // v.1.2
1353+
$req .= pack ( "N", strlen($opts["html_strip_mode"]) ) . $opts["html_strip_mode"];
13341354

13351355
// documents
13361356
$req .= pack ( "N", count($docs) );
@@ -1507,6 +1527,7 @@ function UpdateAttributes ( $index, $attrs, $values, $mva=false )
15071527
}
15081528

15091529
// build request
1530+
$this->_MBPush ();
15101531
$req = pack ( "N", strlen($index) ) . $index;
15111532

15121533
$req .= pack ( "N", count($attrs) );
@@ -1531,18 +1552,28 @@ function UpdateAttributes ( $index, $attrs, $values, $mva=false )
15311552

15321553
// connect, send query, get response
15331554
if (!( $fp = $this->_Connect() ))
1555+
{
1556+
$this->_MBPop ();
15341557
return -1;
1558+
}
15351559

15361560
$len = strlen($req);
15371561
$req = pack ( "nnN", SEARCHD_COMMAND_UPDATE, VER_COMMAND_UPDATE, $len ) . $req; // add header
15381562
if ( !$this->_Send ( $fp, $req, $len+8 ) )
1563+
{
1564+
$this->_MBPop ();
15391565
return -1;
1566+
}
15401567

15411568
if (!( $response = $this->_GetResponse ( $fp, VER_COMMAND_UPDATE ) ))
1569+
{
1570+
$this->_MBPop ();
15421571
return -1;
1572+
}
15431573

15441574
// parse response
15451575
list(,$updated) = unpack ( "N*", substr ( $response, 0, 4 ) );
1576+
$this->_MBPop ();
15461577
return $updated;
15471578
}
15481579

@@ -1619,8 +1650,39 @@ function Status ()
16191650
$this->_MBPop ();
16201651
return $res;
16211652
}
1653+
1654+
//////////////////////////////////////////////////////////////////////////
1655+
// flush
1656+
//////////////////////////////////////////////////////////////////////////
1657+
1658+
function FlushAttributes ()
1659+
{
1660+
$this->_MBPush ();
1661+
if (!( $fp = $this->_Connect() ))
1662+
{
1663+
$this->_MBPop();
1664+
return -1;
1665+
}
1666+
1667+
$req = pack ( "nnN", SEARCHD_COMMAND_FLUSHATTRS, VER_COMMAND_FLUSHATTRS, 0 ); // len=0
1668+
if ( !( $this->_Send ( $fp, $req, 8 ) ) ||
1669+
!( $response = $this->_GetResponse ( $fp, VER_COMMAND_FLUSHATTRS ) ) )
1670+
{
1671+
$this->_MBPop ();
1672+
return -1;
1673+
}
1674+
1675+
$tag = -1;
1676+
if ( strlen($response)==4 )
1677+
list(,$tag) = unpack ( "N*", $response );
1678+
else
1679+
$this->_error = "unexpected response length";
1680+
1681+
$this->_MBPop ();
1682+
return $tag;
1683+
}
16221684
}
16231685

16241686
//
1625-
// $Id: sphinxapi.php 2055 2009-11-06 23:09:58Z shodan $
1687+
// $Id: sphinxapi.php 2376 2010-06-29 14:08:19Z shodan $
16261688
//

0 commit comments

Comments
 (0)