php操作sphinx

ubuntu下的sphinx安装

sphinx安装:sudo apt-get install sphinxsearch

配置sphinx
进入/etc/sphinx/search
cp sphinx-min.conf.disc sphinx.conf
(sphinx-min.conf.disc是模板文件sphinx.conf是配置文件)
配置文件讲解:
source src1:主数据源
index test1 主数据索引
indexer 索引器大小
searchd:开启服务配置(端口等)



建立索引:indexer --all --rotate 可以在不停止sphinx下重新索引


创建主索引:

    bin/indexer --config etc/sphinx.conf hx_9enjoy --rotate

创建增量索引:

    bin/indexer --config etc/sphinx.conf delta --rotate

合并主索引和增量索引:

    bin/indexer --config etc/sphinx.conf --merge hx_9enjoy delta --merge-dst-range deleted 0 0 --rotate

---------------------------------------------------------------

//记住包含sphinxapi类库
include('sphinxapi.class.php');

$s = new SphinxClient;
$s->setServer("localhost", 9312);                //连接sphinx
$s->setMatchMode(SPH_MATCH_EXTENDED2);           //设置sphinx匹配模式
$vid=2611673721;
//$svid=$this->network->shortgz($vid);

//$s->setLimits(1,10);                            //设置sphinx返回数目
$s->SetFiltr('gender',array(0));                   //设置sphinx过滤条件 0为男 gender为字段
$result = $s->query($svid,"users",30);             //在sphinx里通过用户uid查询



$num=$result["total_found"];                       //sphinx返回条数

$str=join(',',array_keys($result['matches']));     //取得id去数据库中in

print_r($result);




//sphinx中文文档
//http://www.coreseek.cn/docs/coreseek_4.1-sphinx_2.0.1-beta.html#api-func-setfilter

//即时索引和索引合并(待续)

原文地址:https://www.cnblogs.com/xiongwei89/p/2971486.html