2010年3月25日 星期四

sphinx for freebsd 完整安裝流程 (3)

接下來就是我們的重頭戲了,安裝mysql51-server以及sphinx-for-chinese
下載網址如下:
sphinx(原始網站)
sphinx-for-chinese
mysql51-server(要下載source code)

第 1 步,先解壓縮 2 個壓縮檔
tar -zxvf sphinx-for-chinese-0.9.9-r2117.tar.gz
tar -zxvf mysql-5.1.45.tar.gz

第 2 步,安裝sphinxse engine,參閱 MySQL storage engine (SphinxSE)
# copy storage to mysql directory
cp -R sphinx-for-chinese-0.9.9-r2117/mysqlse mysql-5.1.45/storage/sphinx
# run script
cd mysql-5.1.45/
sh BUILD/autorun.sh
# configure
./configure \
--with-plugins=sphinx \
--with-low-memory
make
make install
第 3 步,安裝完後,我們也是要檢查MySQL有沒有成功的將 sphinx engine type 安裝進去
# adduser
pw user add mysql
# 初始化資料庫
/usr/local/bin/mysql_install_db
# 更改權限
chown -R mysql:mysql /usr/local/var
# 啟動 mysql
/usr/local/share/mysql/mysql.server start
# 先建立 mysql root 的密碼(記得要先啟動 mysql)
mysqladmin -u root password '000000'

# 登入 mysql
mysql -u root -p

# 查詢 engine type
show engines;

mysql< show engines;
+------------+---------+-----------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                   | Transactions | XA   | Savepoints |
+------------+---------+-----------------------------------------------------------+--------------+------+------------+
| CSV        | YES     | CSV storage engine                                        | NO           | NO   | NO         |
| SPHINX     | YES     | Sphinx storage engine 0.9.9                               | NO           | NO   | NO         |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables | NO           | NO   | NO         |
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance    | NO           | NO   | NO         |
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                     | NO           | NO   | NO         |
+------------+---------+-----------------------------------------------------------+--------------+------+------------+
5 rows in set (0.00 sec)
接下來要建立 sphinx 的 table ,這時候 phpmyadmin 就用的上了,執行下面的 SQL 語法(要先將 index 建好)
CREATE TABLE t1
(
    id          INTEGER UNSIGNED NOT NULL,
    weight      INTEGER NOT NULL,
    query       VARCHAR(3072) NOT NULL,
    group_id    INTEGER,
    INDEX(query)
) ENGINE=SPHINX CONNECTION="sphinx://localhost:9312/test";
-- sphinx://[hostname]:[port]/[index] 

第 4 步,安裝 sphinx-for-chines
首先,為了方便管理檔案,我會將安裝的目錄固定在 /usr/local/sphinx
cd sphinx-for-chinese-0.9.9-r2117
./configure --prefix=/usr/local/sphinx
make
make install
再來就是要將辭典檔轉換為繁體中文的格式,因為作者給的辭典檔是簡體中文。這邊就請大家自行找轉換的程式。
轉換完後,利用作者附的工具轉成可用的字典檔。
/usr/local/sphinx/bin/mkdict xdict_1.1.txt /usr/local/sphinx/etc/xdict
接下來就請設定 sphinx.conf 的內容。

沒有留言: