MySQL SphinxSE and PHP Sphinx Extension

Sphinx a full-text search engine

ตอนนี้ Server นิ่งแล้ว ก็เลยมีเวลามาทำ R&D เกี่ยวกับระบบ Search
เพื่่อนตั้ม (http://www.thaiajax.com) โปเกม่อนเทพ แนะนำ
ว่าให้เอา Sphinx มาช่วย ก็เลยต้องเป็นหน้าที่ผม ที่ต้องทำ Server
ให้ Support หาข้อมูลได้น้อยมากเกี่ยวกับตัว Sphinx ยิ่งในไทย
เท่าที่เห็น ยังไม่มีเลย เพราะคงไม่ต้องใช้ถึงขนาดนี้ ระบบไม่ใหญ่ ..
นั่งงมอยู่นานเหมือนกัน เพราะไม่เคยใช้ หาอ่าน Doc ของเว็บ Sphinx
ก็มีให้อ่านน้อยมาก ๆ แต่เว็บอื่น ๆ มีอยู่พอสมควร ..

ตอนนี้เรื่องการใช้งานการปรับแต่งอะไร ก็กำลัง test กันอยู่ ผมเอา
วิธีการ config มาให้เพื่อน ๆ ที่สนใจได้อ่านกันละกัน เพราะว่ากว่าที่
ผมจะ config ได้ ก็ใช้เวลาพอสมควรเหมือนกัน เลยเอามาแบ่งปัน ..

Install MySQL SphinxSE CentOS 5.2

yum -y install bison patch automake libtool

wget http://www.sphinxsearch.com/downloads/sphinx-0.9.8.tar.gz
wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.67.tar.gz/from/http://mysql.thaiweb.net/
tar xfz sphinx*
tar xfz mysql*

cd mysql*
patch -p1 < ../sphinx-0.9.8/mysqlse/sphinx.5.0.37.diff
BUILD/autorun.sh
mkdir sql/sphinx
cp ../sphinx-0.9.8/mysqlse/* sql/sphinx
./configure –prefix=/usr/local/mysql –with-sphinx-storage-engine
make
make install

cp support-files/mysql.server /etc/init.d/
/etc/init.d/mysql.server start

mysql> SHOW ENGINES;
+————+———+—————————————————————-+
| Engine | Support | Comment |
+————+———+—————————————————————-+
| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables |
| InnoDB | YES | Supports transactions, row-level locking, and foreign keys |
| BerkeleyDB | NO | Supports transactions and page-level locking |
| BLACKHOLE | NO | /dev/null storage engine (anything you write to it disappears) |
| EXAMPLE | NO | Example storage engine |
| ARCHIVE | NO | Archive storage engine |
| CSV | NO | CSV storage engine |
| SPHINX | YES | Sphinx storage engine 0.9.8 |
| ndbcluster | NO | Clustered, fault-tolerant, memory-based tables |
| FEDERATED | NO | Federated MySQL storage engine |
| MRG_MYISAM | YES | Collection of identical MyISAM tables |
| ISAM | NO | Obsolete storage engine |
+————+———+—————————————————————-+
13 rows in set (0.00 sec)

Install Sphinx

cd ../sphinx*
./configure --prefix=/usr/local/sphinx --with-mysql
make
make install

cd api/libsphinxclient
chmod +x buildconf.sh
./buildconf.sh
./configure
make
make install

Install PHP Sphinx extension
http://pecl.php.net/package/sphinx


cd ../../../
wget http://th.php.net/get/php-5.2.6.tar.gz/from/this/mirror
wget http://pecl.php.net/get/sphinx-0.2.0.tgz

tar xfz php-5.2.6.tar.gz
tar xfz sphinx-0.2.0.tgz
mv sphinx-0.2.0 php-5.2.6/ext/sphinx
rm configure
./buildconf –force
./configure –with-apxs2=/usr/local/apache/bin/apxs –with-mysql=/usr/local/mysql –enable-force-cgi-redirect –with-gettext –with-zlib-dir=/usr/local/zlib –enable-mbstring –with-curl=/usr/local/lib –with-sphinx
make
make install

ทำนี้ก็เป็นอันเรียบร้อยแล้วครับ สำหรับ MySQL+SphinxSE
และ PHP Sphinx Extension