CoreSeek是一款專門為中文免費開源的中文全文檢索系統,它是一個支持Tb級的全文數據索引了,下面我們來看看CoreSeek Mysql 安裝與測試.
CoreSeek安裝比較麻煩,官方手冊對此的支持并不算很好,CoreSeek是基于Sphinx的中文的分詞和全文檢索軟件,本文是在MAC OS X系統下安裝和調試CoreSeek.
安裝過程中報錯如果是警告warning則忽略,如果是錯誤error,則必須要處理,CoreSeek是支持三種數據來源的,一種是眾所周知的Mysql,一種是XML文件,另一種是Python,而Python則是萬能數據類型,在本CoreSeek安裝測試教程中只示例數據源是XML文件和MYSQL.
官方手冊地址:http://www.coreseek.cn/products-install/install_on_macosx
一、設置環境變量
- $ export PATH=/usr/local/bin:$PATH
- $ export LC_ALL=zh_CN.UTF-8
- $ export.UTF-8
二、安裝依賴庫:m4、autoconf、automake、libtool。
注意:不要brew install 來安裝,因為對安裝的庫的版本有要求.
- $ curl -O -L http://mirrors.kernel.org/gnu/m4/m4-1.4.13.tar.gz
- $ tar -xzvf m4-1.4.13.tar.gz
- $ cd m4-1.4.13
- $ sudo ./configure --prefix=/usr/local/opt
- $ sudo make
- $ sudo make install
- $ cd ..
- $ curl -O -L http://mirrors.kernel.org/gnu/autoconf/autoconf-2.65.tar.gz
- $ tar -xzvf autoconf-2.65.tar.gz
- $ cd autoconf-2.65
- $ sudo ./configure --prefix=/usr/local/opt
- $ sudo make
- $ sudo make install
- $ cd ..
- $ curl -O -L http://mirrors.kernel.org/gnu/automake/automake-1.11.tar.gz
- $ tar xzvf automake-1.11.tar.gz
- $ cd automake-1.11
- $ ./configure --prefix=/usr/local/opt
- $ sudo make
- $ sudo make install
- $ cd ..
- $ curl -O -L http://mirrors.kernel.org/gnu/libtool/libtool-2.2.6b.tar.gz
- $ tar xzvf libtool-2.2.6b.tar.gz
- $ cd libtool-2.2.6b
- $ sudo ./configure --prefix=/usr/local/opt
- $ sudo make
- $ sudo make install
- $ cd ..
三、安裝Mysql
1、mysql 的安裝自行安裝
2、查找mysql頭文件地址和庫文件地址,我用brew install mysql,安裝的Mysql,頭文件地址和庫文件地址分別是/usr/local/Cellar/mysql/5.6.17_1/include/mysql 和 /usr/local/Cellar/mysql/5.6.17_1/lib
頭文件地址就是mysql.h所在的目錄,庫文件地址就是libmysqlclient.a所在的目錄.
四、下載Coreseek
- $ curl -O -L http://www.coreseek.cn/uploads/csft/3.2/coreseek-3.2.14.tar.gz
- $ tar xzvf coreseek-3.2.14.tar.gz
- $ cd coreseek-3.2.14
在coreseek-3.2.14文件夾下有mmseg和csft和testpack,mmseg是分詞服務,csft是CoreSeek的核心服務,testpack是測試用例.
五、安裝mmseg
- $ cd mmseg-3.2.14
- $ sudo ./bootstrap
- $ sudo ./configure --prefix=/usr/local/opt/mmseg3
- $ sudo make
- $ sudo make install
- $ cd ..
在make的時候,可能會報錯,如下.
- file included from css/ThesaurusDict.cpp:6:
- ../src/css/ThesaurusDict.h:12:17: error: expected namespace name
- using namespace __gnu_cxx;
- ^
- css/ThesaurusDict.cpp:79:15: warning: result of comparison against a string
- literal is unspecified (use strncmp instead) [-Wstring-compare]
- if (filename == "-") {
- ^ ~~~
- css/ThesaurusDict.cpp:116:15: warning: result of comparison against a string
- literal is unspecified (use strncmp instead) [-Wstring-compare]
- if (filename != "-") {
- ^ ~~~
- 2 warnings and 1 error generated.
- make[2] : *** [ThesaurusDict.lo] Error 1
- make[1]: *** [install-recursive] Error 1
這個時候make進程已經終止,原因是因為編譯器版本太高導致的,修改方法:1是降低編譯器版本,反正我打死也不愿意,方法2如下:
- vim src/css/ThesaurusDict.h
- ###在頭部找到:#include <string>
- ###再其下加入一行代碼:
- #include <ext/hash_map>
修改完后保存退出,繼續重新sudo make一下,就沒有error級錯誤了,然后sudo make install即可.
六、安裝coreseek
- $ cd csft-3.2.14
- $ sudo sh buildconf.sh
- $ sudo ./configure --prefix=/usr/local/opt/coreseek --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/opt/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/opt/mmseg3/lib/ --with-mysql --with-mysql-includes=/usr/local/Cellar/mysql/5.6.17_1/include/mysql --with-mysql-libs=/usr/local/Cellar/mysql/5.6.17_1/lib
- $ sudo make //Vevb.com
- $ sudo make install
- $ cd ..
在./configure時,參數--with-mysql-includes是mysql頭文件位置,--with-mysql-libs是mysql庫文件位置,請在本CoreSeek安裝教程第三步所記錄的mysql頭文件地址和庫文件地址,替換.
在make時,可能又會出現error級的錯誤,如果出現make程序是停止運行的,必須要修改,錯誤提示如下:
- phinxexpr.cpp:1047:11: error: use of undeclared identifier 'ExprEval'
- T val = ExprEval ( this->m_pArg, tMatch ); // 'this' fixes gcc ...
解決方法:修改源代碼.
vim src/sphinxexpr.cpp
將T val = ExprEval(this->m_pArg,tMatch)替換為T val = this->ExprEval(this->m_pArg,tMatch).
就是加了個“this->”,是把這個文件中所有的ExprEval()函數都修改了,有三四個吧,修改后保存退出,重新sudo make,然后sudo make install即可.
七、測試XML數據
- $ cd testpack
- #測試編碼是否正確顯示中文,如果不是中文則請看本CoreSeek安裝測試教程第一步
- $ cat var/test/test.xml
- # 測試mmseg分詞的效果
- $ /usr/local/opt/mmseg3/bin/mmseg -d /usr/local/opt/mmseg3/etc var/test/test.xml
- # 建立檢索的索引。
- $ /usr/local/opt/coreseek/bin/indexer -c etc/csft.conf --all
- #全文搜索“網絡搜索”
- $ /usr/local/opt/coreseek/bin/search -c etc/csft.conf 網絡搜索
- 如果在建立檢索的索引出錯,FATAL: failed to lock var/data/xml.spl: Resource temporarily unavailable, will not index. Try --rotate option.
- 則修改為
- $ /usr/local/opt/coreseek/bin/indexer -c etc/csft.conf --all --rotate
八、測試MYSQL數據源
cd testpack
1、修改配置文件,文件位于testpack/etc/csft_mysql.conf
vim etc/csft_mysql.conf
我的csft_mysql.conf文件如下:記得把mysql 的sql_host,sql_user,sql_pass,sql_db,sql_port修改為自己的,并且把路勁都修改為你自己的路徑.
MySQL數據源配置,詳情請查看:http://www.coreseek.cn/products-install/mysql/,請先將var/test/documents.sql導入數據庫,并配置好以下的MySQL用戶密碼數據庫.
- #源定義
- source mysql
- {
- type = mysql
- sql_host = localhost
- sql_user = root
- sql_pass = 8823150
- sql_db = test
- sql_port = 3306
- sql_query_pre = SET NAMES utf8
- sql_query = SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content FROM documents
- #sql_query第一列id需為整數
- #title、content作為字符串/文本字段,被全文索引
- sql_attr_uint = group_id #從SQL讀取到的值必須為整數
- sql_attr_timestamp = date_added #從SQL讀取到的值必須為整數,作為時間屬性
- sql_query_info_pre = SET NAMES utf8 #命令行查詢時,設置正確的字符集
- sql_query_info = SELECT * FROM documents WHERE id=$id #命令行查詢時,從數據庫讀取原始數據信息
- }
- #index定義
- index mysql
- {
- source = mysql #對應的source名稱
- path = /Users/lane/coreseek-3.2.14/testpack/var/data/mysql #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
- docinfo = extern
- mlock = 0
- morphology = none
- min_word_len = 1
- html_strip = 0
- #中文分詞配置,詳情請查看:http://www.coreseek.cn/products-install/coreseek_mmseg/
- charset_dictpath = /usr/local/opt/mmseg3/etc/ #BSD、Linux環境下設置,/符號結尾
- #charset_dictpath = etc/ #Windows環境下設置,/符號結尾,最好給出絕對路徑,例如:C:/usr/local/coreseek/etc/...
- charset_type = zh_cn.utf-8
- }
- #全局index定義
- indexer
- {
- mem_limit = 128M
- }
- #searchd服務定義
- searchd
- {
- listen = 9312
- read_timeout = 5
- max_children = 30
- max_matches = 1000
- seamless_rotate = 0
- preopen_indexes = 0
- unlink_old = 1
- pid_file = /Users/lane/coreseek-3.2.14/testpack/var/log/searchd_mysql.pid #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
- log = /Users/lane/coreseek-3.2.14/testpack/var/log/searchd_mysql.log #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
- query_log = /Users/lane/coreseek-3.2.14/testpack/var/log/query_mysql.log #請修改為實際使用的絕對路徑,例如:/usr/local/coreseek/var/...
- }
2、給mysql導入測試數據
mysql的測試數據我們用的是test數據庫,documents數據表,請自行確保test數據庫存在,我們一起來建documents表,這個表的結構和數據都是由CoreSeek提供的,在testpack/var/test/documents.sql.
- mysql -u root -p
- #輸入密碼
- #看看,數據庫test在不在
- mysql > show databases;
- #如果test庫不在請創建
- mysql > create database test;
- use test;
- #導入數據
- source /Users/lane/coreseek-3.2.14/testpack/var/test/documents.sql
3、測試:
- $ cd testpack
- # 建立檢索的索引
- $ /usr/local/opt/coreseek/bin/indexer -c etc/csft_mysql.conf --all
- #全文搜索“網絡搜索”
- $ /usr/local/opt/coreseek/bin/search -c etc/csft_mysql.conf 網絡搜索
如果提示有錯誤,請檢查csft_mysql.conf的路徑、mysql的配置等信息是否正確.
九、測試PHP+MYSQL
1、先啟動服務
/usr/local/opt/coreseek/bin/searchd -c etc/csft.conf
2、PHP文件
- <?php
- require ( "/Users/lane/coreseek-3.2.14/testpack/api/sphinxapi.php" );
- //Vevb.com
- $cl = new SphinxClient ();
- $cl->SetServer ( '127.0.0.1', 9312);
- $cl->SetConnectTimeout ( 3 );
- $cl->SetArrayResult ( true );
- $cl->SetMatchMode ( SPH_MATCH_ANY);
- $res = $cl->Query ( '網絡搜索', "*" );
- print_r($cl);
- print_r($res);
- ?>
我在Linux折騰了一天沒有搞定,在MAC搞了半天搞定了,等搞定Linux后再發Linux的.
新聞熱點
疑難解答