Sphinx is a high-performance SQL-based full-text search engine. Its performance is among the best in the field of full-text search engines. With Sphinx, we can implement more professional search functions than the database itself, and there are many targeted performance optimizations available.

Features of Sphinx

  • Fast index creation: an index of nearly 1 million records can be created in about 3 minutes. Moreover, incremental indexing is used, making index rebuilding very fast.
  • Lightning-fast retrieval speed: even with a large amount of data like 10 million records, query speed is still at the millisecond level. For 2-4 GB of text, the average query time is less than 0.1 seconds.
  • Search APIs have been designed for many scripting languages, such as PHP, Python,Perl, Ruby, etc. Therefore, you can conveniently call Sphinx's related interfaces in most programming applications.
  • A storage engine plugin has been designed for MySQL. Therefore, if you use Sphinx with MySQL, it couldn't be more convenient.
  • Supports distributed search, allowing horizontal scaling of system performance.

PHP+MySQL+Sphinx Search Engine Architecture Diagram

Installing Sphinx in MySQL

There are two ways to install Sphinx on MySQL:

  • The first way is to use API calls. We can use PHP, Python,Perl, Ruby and other programming languages' API functions to perform queries. This way does not require recompiling MySQL, involves fewer changes between modules, and is relatively flexible.
  • The second way requires recompiling MySQL and compiling Sphinx into MySQL as a plugin. This way requires fewer changes to the program — you only need to modify SQL statements. However, the prerequisite is that your MySQL version must be 5.1 or higher.

The following is the first installation method:

#下载最新稳定版
wget http://www.sphinxsearch.com/downloads/sphinx-0.9.9.tar.gz
tar xzvf sphinx-0.9.9.tar.gz
cd sphinx-0.9.9
./configure --prefix=/usr/local/sphinx/   --with-mysql  --enable-id64
make
make install

Installing the Sphinx Chinese Word Segmentation Plugin Coreseek

Note: The installation tutorial for coreseek comes fromhere, the detailed process is as follows:

Installing and Upgrading autoconf

Because coreseek requires autoconf version 2.64 or higher, you need to upgrade autoconf; otherwise, errors will occur. Fromhttp://download.chinaunix.net/download.php?id=29328&ResourceID=648Download autoconf-2.64.tar.bz2. The installation method is as follows:

tar -jxvf autoconf-2.64.tar.bz2
cd autoconf-2.64
./configure
make
make install

Downloading coreseek

The new version of coreseek puts the dictionary and Sphinx source code in one package, so you only need to download the coreseek package.

wget http://www.wapm.cn/uploads/csft/3.2/coreseek-3.2.14.tar.gz

Installing mmseg (the dictionary used by coreseek)

tar xzvf coreseek-3.2.14.tar.gz
cd mmseg-3.2.14
./bootstrap    #输出的warning信息可以忽略,如果出现error则需要解决
./configure --prefix=/usr/local/mmseg3
make && make install
cd ..

Installing coreseek (Sphinx)

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
make && make install
cd ..

Testing mmseg word segmentation and coreseek search

Note: You need to set the character set to zh_CN.UTF-8 in advance to ensure Chinese displays correctly. My system character set is en_US.UTF-8, which also works.

cd testpack
cat var/test/test.xml  #此时应该正确显示中文
/usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc var/test/test.xml
/usr/local/coreseek/bin/indexer -c etc/csft.conf --all
/usr/local/coreseek/bin/search -c etc/csft.conf 网络搜索
此时正确的应该返回
words:
1. '网络': 1 documents, 1 hits
2. '搜索': 2 documents, 5 hits

Generating the mmseg dictionary and configuration files

The new version has already generated them automatically.

Summary

As a high-performance SQL full-text search engine, Sphinx is worth continued attention from developers, especially its multi-language API support, which makes it easier for developers to use.

Source:http://www.codeceo.com/article/sphinx-sql-search-engine.html
Author: Manong.com – Xiaofeng