This article mainly introduces an example of combining php and coreseek. Friends who are interested in how to connect php to coreseek can refer to it.
The following is the code
<?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; } } ?>
Related recommendations:
Compile and install Sphinx, Chinese word segmentation coreseek and PHP's sphinx extension
coreseek (sphinx) Mysql Thinkphp Detailed explanation of building a Chinese search engine
coreseek configuration and incremental index merge index
The above is the detailed content of How to connect coreseek in php. For more information, please follow other related articles on the PHP Chinese website!