/**
  * Reset settings sphinx
  */
 public function resetClient()
 {
     $this->_client->resetFilters();
     $this->_client->resetGroupBy();
     $this->_client->setArrayResult(false);
     //DEPRECATED: Do not call this method or, even better, use SphinxQL instead of an API
     //$this->_client->setMatchMode(SPH_MATCH_EXTENDED2);
     $this->_client->setLimits(0, 20, 1000, 0);
     $this->_client->setFieldWeights(array());
     $this->_client->setSortMode(SPH_SORT_RELEVANCE, '');
     $this->_client->_error = '';
     $this->_client->_warning = '';
 }
 public function search(Request $request)
 {
     //$keyword = '服务器';
     //$keywords = $requests->get('keywords');
     //$requests = $request;
     //return $requests->get('keywords')->toString();
     $keyword = $request->get('keywords');
     //$keyword = $keywords ? addslashes($keywords) : addslashes($_REQUEST['keywords']);
     //header("content-type:text/html;charset=utf-8");
     // include('/home/tmp/tool/coreseek-3.2.14/csft-3.2.14/api/sphinxapi.php');
     $s = new \SphinxClient();
     $s->setServer("localhost", 9312);
     $s->setArrayResult(true);
     // $s->setSelect();
     $s->setMatchMode(SPH_MATCH_ALL);
     $result = $searchList = array();
     if ($keyword) {
         $result = $s->query($keyword, 'test1');
         // 获取检索到的文章id
         $idArr = array();
         $data = $titleArr = array();
         if (isset($result['matches']) && is_array($result['matches'])) {
             foreach ($result['matches'] as $k => $v) {
                 $idArr[] = $v['attrs']['article_id'];
             }
             $idStr = implode(',', $idArr);
             // 查找文章
             $data['articles'] = \DB::table('blog_articles')->whereRaw('id in (' . $idStr . ')')->get();
             $contentArr = \DB::table('blog_content')->whereRaw('article_id in (' . $idStr . ')')->get();
             if ($contentArr) {
                 $newContentArr = array();
                 foreach ($contentArr as $k => $v) {
                     $newContentArr[$v->article_id] = $v->content;
                 }
                 $contentArr = $newContentArr;
                 unset($newContentArr);
             }
             if ($data['articles']) {
                 foreach ($data['articles'] as $k => $v) {
                     $searchList[$k]['id'] = $v->id;
                     $searchList[$k]['title'] = $v->title;
                     $searchList[$k]['content'] = $contentArr[$v->id];
                 }
             }
             //var_dump($searchList);exit();
             return view('articles.search', compact('searchList'));
         }
     } else {
         $searchList[0]['message'] = '请输入要查询的关键词~';
         return;
     }
     return view('articles.search', compact('searchList'));
     //var_dump(rand(1000,9999));
     //return '';
 }
Ejemplo n.º 3
0
 /**
  * @brief reset search criteria to default
  * @details reset conditions and set default search options
  */
 public function resetCriteria()
 {
     if (is_object($this->criteria)) {
         $this->lastCriteria = clone $this->criteria;
     } else {
         $this->lastCriteria = new stdClass();
     }
     $this->criteria = new stdClass();
     $this->criteria->query = '';
     $this->client->resetFilters();
     $this->client->resetGroupBy();
     $this->client->setArrayResult(false);
     $this->client->setMatchMode($this->matchMode);
     //        $this->client->setRankingMode($this->rankMode);
     $this->client->setSortMode(SPH_SORT_RELEVANCE, '@relevance DESC');
     $this->client->setLimits(0, 1000000, 10000);
     if (!empty($this->fieldWeights)) {
         $this->client->setFieldWeights($this->fieldWeights);
     }
 }