$ /usr/local/coreseek/bin/indexer -c csft.conf test1 // 其中 test1 是配置文件中的索引名
$ /usr/local/coreseek/bin/indexer -c etc/csft.conf --all
$ /usr/local/coreseek/bin/search -c etc/csft.conf 網絡搜索
4. coreseek 命令測試
$ /usr/local/coreseek/bin/indexer -c etc/csft.conf 測試配置是否正確
$ /usr/local/coreseek/bin/indexer -c etc/csft.conf xx 或者 --all爲文件中所有索引項創建索引 加載索引
$ /usr/local/coreseek/bin/search -c etc/csft.conf "測試搜索" 搜索「測試搜索」
$ /usr/local/coreseek/bin/search -c etc/csft.conf "test" 搜索"test"
5. 啓動爲服務
$ /usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft.conf 開始監聽 默認端口爲9312
6. 中止搜索服務
$ /usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft.conf --stop
7. 若是啓動服務,要更新索引
$ /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft.conf --all --rotate
8. 安裝 sphinx 的 php 插件
首先安裝 sphinxcient 客戶端
$ cd /usr/local/src/coreseek-4.1-beta/csft-4.1/api/libsphinxclient
$ ./configure && make && make install
接着安裝 sphinx 插件
$ wget sphinx-1.2.0.tgz
$ tar zxvf sphinx-1.2.0.tgz
$ cd sphinx-1.2.0
$ ./configure
$ make && make install
可能遇到的問題:
1. 若是出現
undefined reference to `libiconv'的相似錯誤,能夠按照以下方法處理:
##方法一:(Linux使用)
## 直接執行:export LIBS="-liconv"
##而後make clean,再次configure後,進行編譯安裝make && make install
## 方法二:
## 首先configure,而後vim src/makefile
## 在其中搜索lexpat,在其後加上 -liconv
## 修改後該行應該爲:-lexpat -liconv -L/usr/local/lib
## 而後再次make && make install
## 方法三:
## 首先configure,而後vim config/config.h
## 在其中搜索USE_LIBICONV,將其後的1修改成0
## 而後再次make && make install
2.
英文字符能夠正常檢索,中文字符不能檢索
##緣由:因爲配置文件錯誤 csft.conf 沒有正確配置 缺乏關鍵的中文分詞支持
##解決辦法:在配置文件中記得加上 sql_query_pre = SET NAMES utf8
在 index 段這裏記得加上 charset_dictpath = /usr/local/mmseg3/etc/ charset_type = zh_cn.utf-8 ngram_len = 0
9. sphinxSE 引擎安裝
mysql支持引擎的在線插拔,因此咱們只須要將引擎文件添加進去便可
cmake安裝
$ wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
$ tar zxvf cmake-2.8.10.2
$ ./configure
$ make && make install
mysql安裝
$ tar zxvf mysql-5.5.27.tar.gz
$ tar zxvf /usr/local/src/coreseek-4.1-beta.tar.gz
$ cp -rf coreseek-4.1-beta/csft-4.1/mysqlse mysql mysql-5.5.27/storage/sphinx
$ cd mysql-5.5.27
$ cmake . -DCMAKE_BUILD_TYPE=Release -DWITH_SPHINX_STORAGE_ENGINE=1
$ make
$ cp storage/sphinx/ha_sphinx.so /usr/local/mysql/lib/plugin/
$ mysql -> install plugin sphinx soname "ha_sphinx.so"; -> show engines; // 出現SPHINX引擎 安裝成功
可能遇到的問題:
1.若是出現 show engines 中已經有sphinxSE引擎,可是沒法添加該引擎的數據庫
##方法:從新編譯安裝mysql
10. 測試
配置好 /usr/local/coreseek/etc/csft.conf 配置文件
$ cat /usr/local/coreseek/etc/csft.conf
source src1
{
type = mysql
sql_host = 192.168.158.145
sql_user = test
sql_pass = test@ptah
sql_db = test
sql_port = 3306 # optional, default is 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_attr_uint = group_id
sql_attr_timestamp = date_added
sql_query_info = SELECT * FROM documents WHERE id=$id
}
index test1
{
source = src1
path = /usr/local/coreseek/var/data/test1
docinfo = extern
charset_dictpath = /usr/local/mmseg3/etc/
charset_type = zh_cn.utf-8
ngram_len = 0
}
indexer
{
mem_limit = 32M
}
searchd
{
port = 9312
log = /usr/local/coreseek/var/log/searchd.log
query_log = /usr/local/coreseek/var/log/query.log
read_timeout = 5
max_children = 30
pid_file = /usr/local/coreseek/var/log/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 0
unlink_old = 1
}
創建好SphinxSE查詢數據表,從/usr/local/src/coreseek-4.1-beta/testpack/var/test/documents.sql 導入到 test 數據庫中
$ mysql> grant all on test.* to test@'%' identified by 'test@ptah';
開啓服務
$ searchd -c /usr/local/coreseek/etc/csft.conf
創建查詢表
$ mysql> create table sphinx( id integer unsigned not null, weight integer not null, query varchar(255) not null, group_id integer, index(query)) engine=sphinx connection="sphinx://192.168.158.145:9312";
咱們這裏能夠直接使用sphinx://192.168.158.145:9312 而不用使用 sphinx://192.168.158.145:9312/test1 不須要在後面加索引名 這樣就能搜索sphinx中的所有數據,在實際應用中 若是數據庫進行了分表操做同時數據源進行定時增量操做,咱們須要爲每個表創建兩個數據源(分別是所有數據索引和增量數據索引),爲多個數據源創建兩個索引(所有索引和增量索引)
例如:有兩個test1,test2表 只要有 source test1; source test2; source test1_incre:test1; source test2_incre:test2; index test(source test1; source test2); index test_incre:test(source test1_incre; source test2_incre;);
執行 SphinxSE 查詢
$ select * from sphinx where query="網絡搜索;mode=any";