php實現搜尋類封裝樣本,php實現封裝樣本_PHP教程

來源:互聯網
上載者:User

php實現搜尋類封裝樣本,php實現封裝樣本


本文為大家分享了php實現搜尋類封裝樣本,供大家參考,具體內容如下

<?php/** * SoClass.php * 索引與搜尋類 */ class SoClass {   private $_xindex;   private $_xsearch;   private $_project;   public function __construct($project){     //載入引導檔案    require_once 'lib/XS.php';    //初始化    $xs = new XS($project);     $this->_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擷取搜尋引擎關鍵字來源的函數(支援百度和Google等搜尋引擎)
  • 有道搜尋和IP138的IP的API介面(PHP應用)
  • PHP屏蔽蜘蛛存取碼及常用搜尋引擎的HTTP_USER_AGENT
  • php中怎麼搜尋相關聯陣列索引值及擷取之
  • ThinkPHP讓分頁保持搜尋狀態的方法
  • jquery+php實現搜尋方塊自動提示
  • Thinkphp搜尋時首頁分頁和搜尋網頁保持條件分頁的方法

http://www.bkjia.com/PHPjc/1117054.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1117054.htmlTechArticlephp實現搜尋類封裝樣本,php實現封裝樣本 本文為大家分享了php實現搜尋類封裝樣本,供大家參考,具體內容如下 php/** * SoClass.php * 索引與搜...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.