CoreSeek详细入门教程
centos6操作系統
Coreseek 是一款中文全文檢索/搜索軟件,以GPLv2許可協議開源發布,基于Sphinx研發并獨立發布,專攻中文搜索和信息處理領域,適用于行業/垂直搜索、論壇/站內搜索、數據庫搜索、文檔/文獻檢索、信息檢索、數據挖掘等應用場景,用戶可以免費下載使用。
coreseek安裝需要預裝的軟件:
yum install make gcc g++ gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel
cd /usr/local/src wget 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##安裝mmseg cd mmseg-3.2.14 ./bootstrap #輸出的warning信息可以忽略,如果出現error則需要解決 ./configure --prefix=/usr/local/mmseg3 make && make install cd .. ## 安裝完成后,mmseg使用的詞典和配置文件將自動安裝到/usr/local/mmseg3/etc中##安裝coreseek cd csft-3.2.14 sh buildconf.sh #輸出的warning信息可以忽略,如果出現error則需要解決 ./configure --prefix=/usr/local/coreseek --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib/ --with-mysql ##如果提示mysql問題,可以查看MySQL數據源安裝說明 make && make install cd ..cd /usr/local/coreseek/etc cp sphinx-min.conf.dist sphinx.conf vi sphinx.conf 內容示例如下(localhost,DB_USER,DB_PASSWORD,DB_NAME自行修改) # # Minimal Sphinx configuration sample (clean, simple, functional) #source content {type = mysqlsql_host = localhostsql_user = DB_USERsql_pass = DB_PASSWORDsql_db = DB_NAMEsql_port = 3306 # optional, default is 3306sql_query_pre = SET NAMES utf8sql_query = \SELECT id, title, pub_time, group_id, content FROM contents where status = '1'sql_attr_uint = group_idsql_attr_timestamp = pub_timesql_query_info = SELECT * FROM contents WHERE id=$id } index content {source = contentpath = /usr/local/coreseek/var/data/contentdocinfo = externcharset_dictpath = /usr/local/mmseg3/etc/charset_type = zh_cn.utf-8ngram_len = 0 } indexer {mem_limit = 32M }searchd {port = 9312log = /usr/local/coreseek/var/log/searchd.logquery_log = /usr/local/coreseek/var/log/query.logread_timeout = 5max_children = 30pid_file = /usr/local/coreseek/var/log/searchd.pidmax_matches = 1000seamless_rotate = 1preopen_indexes = 1unlink_old = 1 }然后根據以上配置建立索引文件
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/sphinx.conf --all --rotate啟動命令
/usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/sphinx.conf
然后在coreseek目錄下,新建3個sh腳本,以便操作
停止服務stop.sh
建立索引build.sh
#!/bin/bash /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/sphinx.conf --all --rotate啟動服務start.sh
#!/bin/bash /usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/sphinx.conf添加可執行權限
chmod +x start.sh chmod +x stop.sh chmod +x build.sh運行start.sh后,使用crontab定時執行build.sh,就可更新索引。(注:因為數據量小且更新不算很頻繁,未使用增量索引,只是定時重建主索引,新版本CoreSeek全文搜索 4.1 支持實時索引)
crontab -e 0 2 * * * sh /usr/local/coreseek/build.sh >/dev/null 2>&1每天凌晨2點重建一次索引,忽略日志輸出。
在/usr/local/src/coreseek.3.2.14/csft-3.2.14/api目錄下提供了PHP的接口文件 sphinxapi.php,這個文件包含一個SphinxClient的類,copy到自己的web目錄下
通過如下方式進行搜索
安裝包括兩個部分,mmseg和csft
安裝成功會在/usr/local文件夾下面出現coreseek文件夾
source bt
{
?sql_pass ???????????????= **** ?#如果密碼里面有#號需要使用轉意字符,否則連接不了數據庫 ?
?sql_query_pre ?= SET NAMES utf8 #要根據你自己數據庫的編碼改變,比如如果編碼是utf8mb4而編碼寫的是utf8 會出現沒有搜索結果的問題
?
}
?
index bt
{
? ? source ? ? ? ? ? ??? ? ? ?= bt ?#這個地方的值要和前面配置的source名對應
}
/usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/sphinx.conf --stop ?停止服務
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/sphinx.conf --all --rotate ?建立索引
/usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/sphinx.conf ??開啟服務
默認配置文件是csft.conf 如果配置文件是其他名字的話,需要-c 來制定配置文件路徑
---------------
配置文件中
sql_query????????????????= ??xxxx
xxxx代表一個sql語句,sql語句select的第一個字段將被sphinx認作表的主鍵來進行索引,所以數據表的主鍵字段不是int類型也沒有關系,選一個是int類型的字段排在select語句的第一個就行了,但是這個字段要保證唯一性,否則會導致搜索結果不完整,計算出來的值也可以被當做主鍵來進行索引 比如SELECT unix_timestamp(time),name, age .......unix_timestamp(time)是計算出來的,它排在第一個的時候,就會被sphinx當做表的主鍵來進行索引。
---------------------?
?
?
總結
以上是生活随笔為你收集整理的CoreSeek详细入门教程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UltraISO9.3.0.2610中文
- 下一篇: java面试题37 关于对象成员占用内存