好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

php调用sphinx综合实列

//Vendor('Coreseek.testpack.api.sphinxapi'); 因为已经加载了扩展。不需要引入

$spx = new \SphinxClient;

//实例化SphinxClient

$spx -> SetServer('123.56.106.40',9312);

//设置连接超时(秒)为searchd连接。

$spx -> SetConnectTimeout ( 3 ); 

// 最大查询时间 单位为ms,毫秒

$spx -> SetMaxQueryTime(20000);

$spx -> SetLimits(0,1000,$max_matches=100000, $cutoff=0); //设置分页

$spx -> SetArrayResult ( true ); //控制搜索结果集的返回格式(匹配项按数组返回还是按hash返回).true 数组返回

$spx -> SetMatchMode(SPH_MATCH_ANY); //设置全文查询的匹配模式. mode 是以下列出的常量之一.

$result = $spx -> query('p','mysql'); //连接到searchd服务器,根据服务器的当前设置执行给定的查询,取得并返回结果集.查询字符串.,索引名称 (可以为多个,使用逗号分割,或者为“*”表示全部索引).

//$ids = join(",",array_keys($result['matches']));

//$sql = "SELECT * FROM shop where id in ({$ids})";

//$stmt = $db->query($sql);

//$r = $stmt->FETCHALL(PDO::FETCH_ASSOC);

//echo "<pre>";

dump($result);

dump($spx);

查看更多关于php调用sphinx综合实列的详细内容...

  阅读:36次