<?php
//
// $Id: sphinxapi.php 2055 2009-11-06 23:09:58Z shodan $
//
//
// Copyright (c) 2001-2008, Andrew Aksyonoff. 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
// received a copy of the GPL license along with this program; if you
// did not, you can find it at http://www.gnu.org/
//
/////////////////////////////////////////////////////////////////////////////
// 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 );
/// current client-side command implementation versions
define ( "VER_COMMAND_SEARCH", 0x116 );
define ( "VER_COMMAND_EXCERPT", 0x100 );
define ( "VER_COMMAND_UPDATE", 0x102 );
define ( "VER_COMMAND_KEYWORDS", 0x100 );
define ( "VER_COMMAND_STATUS", 0x100 );
define ( "VER_COMMAND_QUERY", 0x100 );
/// known searchd status codes
define ( "SEARCHD_OK", 0 );
define ( "SEARCHD_ERROR", 1 );
define ( "SEARCHD_RETRY", 2 );
define ( "SEARCHD_WARNING", 3 );
/// known match modes
define ( "SPH_MATCH_ALL", 0 );
define ( "SPH_MATCH_ANY", 1 );
define ( "SPH_MATCH_PHRASE", 2 );
define ( "SPH_MATCH_BOOLEAN", 3 );
define ( "SPH_MATCH_EXTENDED", 4 );
define ( "SPH_MATCH_FULLSCAN", 5 );
define ( "SPH_MATCH_EXTENDED2", 6 ); // extended engine V2 (TEMPORARY, WILL BE REMOVED)
/// known ranking modes (ext2 only)
define ( "SPH_RANK_PROXIMITY_BM25", 0 ); ///< default mode, phrase proximity major factor and BM25 minor one
define ( "SPH_RANK_BM25", 1 ); ///< statistical mode, BM25 ranking only (faster but worse quality)
define ( "SPH_RANK_NONE", 2 ); ///< no ranking, all matches get a weight of 1
define ( "SPH_RANK_WORDCOUNT", 3 ); ///< simple word-count weighting, rank is a weighted sum of per-field keyword occurence counts
define ( "SPH_RANK_PROXIMITY", 4 );
define ( "SPH_RANK_MATCHANY", 5 );
define ( "SPH_RANK_FIELDMASK", 6 );
/// known sort modes
define ( "SPH_SORT_RELEVANCE", 0 );
define ( "SPH_SORT_ATTR_DESC", 1 );
define ( "SPH_SORT_ATTR_ASC", 2 );
define ( "SPH_SORT_TIME_SEGMENTS", 3 );
define ( "SPH_SORT_EXTENDED", 4 );
define ( "SPH_SORT_EXPR", 5 );
/// known filter types
define ( "SPH_FILTER_VALUES", 0 );
define ( "SPH_FILTER_RANGE", 1 );
define ( "SPH_FILTER_FLOATRANGE", 2 );
/// known attribute types
define ( "SPH_ATTR_INTEGER", 1 );
define ( "SPH_ATTR_TIMESTAMP", 2 );
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 );
/// known grouping functions
define ( "SPH_GROUPBY_DAY", 0 );
define ( "SPH_GROUPBY_WEEK", 1 );
define ( "SPH_GROUPBY_MONTH", 2 );
define ( "SPH_GROUPBY_YEAR", 3 );
define ( "SPH_GROUPBY_ATTR", 4 );
define ( "SPH_GROUPBY_ATTRPAIR", 5 );
// important properties of PHP's integers:
// - always signed (one bit short of PHP_INT_SIZE)
// - conversion from string to int is saturated
// - float is double
// - div converts arguments to floats
// - mod converts arguments to ints
// the packing code below works as follows:
// - when we got an int, just pack it
// if performance is a problem, this is the branch users should aim for
//
// - otherwise, we got a number in string form
// this might be due to different reasons, but we assume that this is
// because it didn't fit into PHP int
//
// - factor the string into high and low ints for packing
// - if we have bcmath, then it is used
// - if we don't, we have to do it manually (this is the fun part)
//
// - x64 branch does factoring using ints
// - x32 (ab)uses floats, since we can't fit unsigned 32-bit number into an int
//
// unpacking routines are pretty much the same.
// - return ints if we can
// - otherwise format number into a string
/// pack 64-bit signed
function sphPackI64 ( $v )
{
assert ( is_numeric($v) );
// x64
if ( PHP_INT_SIZE>=8 )
{
$v = (int)$v;
return pack ( "NN", $v>>32, $v&0xFFFFFFFF );
}
// x32, int
if ( is_int($v) )
return pack ( "NN", $v < 0 ? -1 : 0, $v );
// x32, bcmath
if ( function_exists("bcmul") )
{
if ( bccomp ( $v, 0 ) == -1 )
$v = bcadd ( "18446744073709551616", $v );
$h = bcdiv ( $v, "4294967296", 0 );
$l = bcmod ( $v, "4294967296" );
return pack ( "NN", (float)$h, (float)$l ); // conversion to float is intentional; int would lose 31st bit
}
// x32, no-bcmath
$p = max(0, strlen($v) - 13);
$lo = abs((float)substr($v, $p));
$hi = abs((float)substr($v, 0, $p));
$m = $lo + $hi*1316134912.0; // (10 ^ 13) % (1 << 32) = 1316134912
$q = floor($m/4294967296.0);
$l = $m - ($q*4294967296.0);
$h = $hi*2328.0 + $q; // (10 ^ 13) / (1 << 32) = 2328
if ( $v<0 )
{
if ( $l==0 )
$h = 4294967296.0 - $h;
else
{
$h = 4294967295.0 - $h;
$l = 4294967296.0 - $l;
}
}
return pack ( "NN", $h, $l );
}
/// pack 64-bit unsigned
function sphPackU64 ( $v )
{
assert ( is_numeric($v) );
// x64
if ( PHP_INT_SIZE>=8 )
{
assert ( $v>=0 );
// x64, int
if ( is_int($v) )
return pack ( "NN", $v>>32, $v&0xFFFFFFFF );
// x64, bcmath
if ( function_exists("bcmul") )
{
$h = bcdiv ( $v, 4294967296, 0 );
$l = bcmod ( $v, 4294967296 );
return pack ( "NN", $h, $l );
}
// x64, no-bcmath
$p = max ( 0, strlen($v) - 13 );
$lo = (int)substr ( $v, $p );
$hi = (int)substr ( $v, 0, $p );
$m = $lo + $hi*1316134912;
$l = $m % 4294967296;
$h = $hi*2328 + (int)($m/4294967296);
return pack ( "NN", $h, $l );
}
// x32, int
if ( is_int($v) )
return pack ( "NN", 0, $v );
// x32, bcmath
if ( function_exists("bcmul") )
{
$h = bcdiv ( $v, "4294967296", 0 );
$l = bcmod ( $v, "4294967296" );
return pack ( "NN", (float)$h, (float)$l ); // conversion to float is intentional; int would lose 31st bit
}
// x32, no-bcmath
$p = max(0, strlen($v) - 13);
$lo = (float)substr($v, $p);
$hi = (float)substr($v, 0, $p);
$m = $lo + $hi*1316134912.0;
$q = floor($m / 4294967296.0);
$l = $m - ($q * 4294967296.0);
$h = $hi*2328.0 + $q;
return pack ( "NN", $h, $l );
}
// unpack 64-bit unsigned
function sphUnpackU64 ( $v )
{
list ( $hi, $lo ) = array_values ( unpack ( "N*N*", $v ) );
if ( PHP_INT_SIZE>=8 )
{
if ( $hi<0 ) $hi += (1<<32); // because php 5.2.2 to 5.2.5 is totally fucked up again
if ( $lo<0 ) $lo += (1<<32);
// x64, int
if ( $hi<=2147483647 )
return ($hi<<32) + $lo;
// x64, bcmath
if ( function_exists("bcmul") )
return bcadd ( $lo, bcmul ( $hi, "4294967296" ) );
// x64, no-bcmath
$C = 100000;
$h = ((int)($hi / $C) << 32) + (int)($lo / $C);
$l = (($hi % $C) << 32) + ($lo % $C);
if ( $l>$C )
{
$h += (int)($l / $C);
$l = $l % $C;
}
if ( $h==0 )
return $l;
return sprintf ( "%d%05d", $h, $l );
}
// x32, int
if ( $hi==0 )
{
if ( $lo>0 )
return $lo;
return sprintf ( "%u", $lo );
}
$hi = sprintf ( "%u", $hi );
$lo = sprintf ( "%u", $lo );
// x32, bcmath
if ( function_exists("bcmul") )
return bcadd ( $lo, bcmul ( $hi, "4294967296" ) );
// x32, no-bcmath
$hi = (float)$hi;
$lo = (float)$lo;
$q = floor($hi/10000000.0);
$r = $hi - $q*10000000.0;
$m = $lo + $r*4967296.0;
$mq = floor($m/10000000.0);
$l = $m - $mq*10000000.0;
$h = $q*4294967296.0 + $r*429.0 + $mq;
$h = sprintf ( "%.0f", $h );
$l = sprintf ( "%07.0f", $l );
if ( $h=="0" )
return sprintf( "%.0f", (float)$l );
return $h . $l;
}
// unpack 64-bit signed
function sphUnpackI64 ( $v )
{
list ( $hi, $lo ) = array_values ( unpack ( "N*N*", $v ) );
// x64
if ( PHP_INT_SIZE>=8 )
{
if ( $hi<0 ) $hi += (1<<32); // because php 5
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
软件开发设计:应用软件开发、系统软件开发、移动应用开发、网站开发Node.js、C++、Java、python、web、C#等语言的项目开发与学习资料 硬件与设备:单片机、EDA、proteus、RTOS、包括计算机硬件、服务器、网络设备、存储设备、移动设备等 操作系统:LInux、Android树莓派、安卓开发、微机操作系统、网络操作系统、分布式操作系统等。此外,还有嵌入式操作系统、智能操作系统等。 网络与通信:数据传输、信号处理、网络协议、网络与通信硬件、网络安全网络与通信是一个非常广泛的领域,它涉及到计算机科学、电子工程、数学等多个学科的知识。 云计算与大数据:包括云计算平台、大数据分析、人工智能、机器学习等,云计算是一种基于互联网的计算方式,通过这种方式,共享的软硬件资源和信息可以按需提供给计算机和其他设备。
资源推荐
资源详情
资源评论
收起资源包目录
php实现的基于sphinx搜索引擎的网站统计系统.zip (7个子文件)
cm
etc
analytic.conf 601B
shell
restart.sh 107B
search.php 6KB
common.php 1KB
sphinxapi.php 43KB
source
analytic.php 3KB
.gitignore 38B
共 7 条
- 1
资源评论
妄北y
- 粉丝: 1w+
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功