本篇主要介紹一個php和coreseek結合的例子,有對php如何連結coreseek有興趣的小夥伴參考下。
以下是程式碼
<?php require_once AN_ROOT."/inc/sphinxapi.php"; require_once AN_ROOT."/res/adodb/adodb.inc.php"; $keywords = $_REQUEST['keywords']; $info = getInfoCoreSeek($keywords,$_GET['page']); function getInfoCoreSeek($keywords,$page=1) { $mode = SPH_MATCH_ANY; $host = "localhost"; $port = 3312; $index = "*"; $limit = 4; $ranker = SPH_RANK_PROXIMITY_BM25; if(!$page) $page=1; $page = intval($page); $off = ($page-1)*$limit; $cl = new SphinxClient (); $cl->SetServer ( $host, $port ); $cl->SetConnectTimeout ( 1 ); $cl->SetWeights ( array ( 100, 1 ) ); $cl->SetMatchMode ( $mode ); $cl->SetLimits ( $off, $limit, ( $limit>10000 ) ? $limit : 10000 ); $cl->SetRankingMode ( $ranker ); $cl->SetArrayResult ( true ); $res = $cl->Query ( join(" ", $keywords), $index ); if($res) { $pageL = PageQuery($res['total'],$page,4,"act=search&keywords=".$_REQUEST['keywords']); foreach($res['matches'] as $v) { $arrID[] = $v['id']; } $rs = $GLOBALS['db']->GetAll("select id,title,content from info where id in(".join(',', $arrID).")"); $GLOBALS['tpl']->assign('pageL', $pageL); //echo '<pre class="brush:php;toolbar:false">'; //print_r($res); //echo ''; return $rs; } } ?>
相關推薦:
linux下編譯安裝Sphinx、中文分詞coreseek及PHP的sphinx擴充
coreseek (sphinx) Mysql Thinkphp搭建中文搜尋引擎詳解
以上是php如何連接coreseek的詳細內容。更多資訊請關注PHP中文網其他相關文章!