php全文檢索搜尋引擎xunsearch的搭建

來源:互聯網
上載者:User

標籤:php   搜尋引擎   sunsearch   關鍵詞匹配   

    1.運行下面指令下載、解壓安裝包

wget http://www.xunsearch.com/download/xunsearch-full-latest.tar.bz2tar -xjf xunsearch-full-latest.tar.bz2

    2.執行安裝指令碼,根據提示進行操作,主要是輸入 xunsearch 軟體包的安裝目錄,強烈建議單獨 規劃一個目錄,而不是混到別的軟體目錄中。

cd xunsearch-full-1.3.0/sh setup.sh

第一次安裝的話,過程可能會稍顯漫長,請不必著急,您大可泡杯茶一邊喝一邊等待即可。

    執行該步驟時,有可能會出現如下兩種錯誤資訊:

    ERROR: failed to configure xapian-core-scws, see ‘setup.log‘ for more detail

    ERROR: failed to configure scws, see ‘setup.log‘ for more detail

    解決辦法:1.安裝g++:yum install gcc-c++

              2.安裝zlib模組:yum install zlib-devel

3.待命令運行結束後,如果沒有出錯中斷,則表示順利安裝完成,然後就可以啟動/重新啟動 xunsearch 的後台服務,下面命令中的 $prefix 請務必替換為您的安裝目錄,而不是照抄。

cd $prefix ; bin/xs-ctl.sh restart

強烈建議您將此命令添加到開機啟動指令碼中,以便每次伺服器重啟後能自動啟動搜尋服務程式, 在 Linux 系統中您可以將指令碼指令寫進 /etc/rc.local 即可。

執行該步驟時,在第一次執行restart時會執行不成功,那麼請用相同的命令重試一下


4.此時的xunsearch服務已經安裝並啟動完成了,接下來是資料的匯入

4.1首先編輯sdk中app/demo.ini檔案的配置,參考官網手冊:http://www.xunsearch.com/doc/php/guide/ini.first


[id] type=id             [name] type=title          [name] type=body        (括弧內的key為資料庫中或csv資料中的key值)



4.2將資料匯入。匯入資料有多種方式,一個是通過mysql串連匯入資料(util目錄在sdk裡面):util/Indexer.php --source=mysql://root:密碼(沒有則為空白)@127.0.0.1/blog/blog --clean demo 另一種方式是通過csv匯入資料:util/Indexer.php --source=csv --file=./tages.csv --clean demo



5.命令列中體驗效果:util/Quest.php demo "成龍"



6.php代碼實現全文檢索搜尋:

<?phpclass Aj_Mblog_SearchController extends AbstractController {    public function indexAction(){        require ‘/usr/local/xunsearch/sdk/php/lib/XS.php‘;        $xs = new XS(‘demo‘);        $search = $xs->search; // 搜尋對象來自 XS 的屬性        $query = ‘測試‘; // 這裡的搜尋語句很簡單,就一個短語        $search->setQuery($query); // 設定搜尋語句        $docs = $search->search(); // 執行搜尋,將搜尋結果文檔儲存在 $docs 數組中        $count = $search->count(); // 擷取搜尋結果的匹配總數估算值        $res = $docs[0];        echo $res->id;die;        var_dump($docs[0]);die;        print_r($docs);        echo $count;    }}?>


更過xunsearch教程見:http://www.xunsearch.com/



本文出自 “PHP程式猿” 部落格,轉載請與作者聯絡!

php全文檢索搜尋引擎xunsearch的搭建

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.