_project = $project; $this->_xindex = $xs->index; $this->_xsearch = $xs->search; $this->_xsearch->setcharset('utf-8'); } public function query($keyword,$row=20,$jnum=0){ $xs = new xs($this->_project); $xs->search->setfuzzy(); $xs->search->setautosynonyms(); $xs->search->setquery($keyword); //支持同义词搜索,默认打开 $xs->search->setlimit($row, $jnum); //设置返回结果最多为 5 条,并跳过前 10 条 $docs = $xs->search->search(); //执行搜索,将搜索结果文档保存在 $docs 数组中 $count = $xs->search->count(); //获取搜索结果的匹配总数估算值 if($count){ $data = array(); foreach ($docs as $key=>$doc){ $data[$key]['pid'] = $doc->pid; $data[$key]['nid'] = $doc->nid; $data[$key]['category'] = $doc->category; $data[$key]['url'] = $doc->url; $data[$key]['name'] = $xs->search->highlight(htmlspecialchars($doc->name)); $data[$key]['message'] = $xs->search->highlight(htmlspecialchars($doc->message)); } return array('data'=>$data,'count'=>$count); } return array(); } public function hotword($num,$type='lastnum'){ return $this->_xsearch->gethotquery($num,$type); } public function expanded($keyword){ return $this->_xsearch->getexpandedquery($keyword); } public function lastcount(){ return $this->_xsearch->getlastcount(); } public function index($data,$update=0){ // 创建文档对象 $doc = new xsdocument; $doc->setfields($data); // 添加或更新到索引数据库中 if(!$update){ $this->_xindex->add($doc); }else{ $this->_xindex->update($doc); } } public function delete($idarray){ //删除索引(主键删除array('1','2','3')) $this->_xindex->del($idarray); } public function addsynonym($word1,$word2){ $this->_xindex->addsynonym($word1,$word2); } public function clearindex(){ $this->_xindex->clean(); } } ?>
以上就是本文的全部内容,希望对大家学习php程序设计有所帮助。
您可能感兴趣的文章:php站内搜索并高亮显示关键字的实现代码php+ajax做仿百度搜索下拉自动提示框(有实例)php写的获取各搜索蜘蛛爬行记录代码php获取搜索引擎关键字来源的函数(支持百度和谷歌等搜索引擎)有道搜索和ip138的ip的api接口(php应用)php屏蔽蜘蛛访问代码及常用搜索引擎的http_user_agentphp中怎么搜索相关联数组键值及获取之thinkphp让分页保持搜索状态的方法jquery+php实现搜索框自动提示thinkphp搜索时首页分页和搜索页保持条件分页的方法
http://www.bkjia.com/phpjc/1117054.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1117054.htmltecharticlephp实现搜索类封装示例,php实现封装示例 本文为大家分享了php实现搜索类封装示例,供大家参考,具体内容如下 php/** * soclass.php * 索引与搜...
