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/archive/2013/03/20/2971486.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值