Home >Backend Development >PHP Tutorial >Compile and install Sphinx, Chinese word segmentation coreseek and PHP sphinx extension under Linux

Compile and install Sphinx, Chinese word segmentation coreseek and PHP sphinx extension under Linux

伊谢尔伦
伊谢尔伦Original
2016-11-25 15:57:222098browse

Linux environment is: CentOS5.5, Ubuntu12.04

1. Software download

sphinx-2.1.3

coreseek-4.1

2. Install sphinx

tar zxvf sphinx-2.1.3.tar.gz //解压sphinx包
cd sphinx-2.1.3
./configure --prefix=/usr/local/sphinx --with-mysql=/usr/local/mysql/

--prefix: Specify the installation path of sphinx
- -with-mysql: Specify the mysql installation path

sudo make && make install

Compile and install

After successful installation, sphinx will form three commands:

indexer 创建索引命令
searchd 启动进程命令
search 命令行搜索命令

Note: The above commands are in the /usr/local/sphinx/bin directory by default

3 , configure sphinx and use

cd /usr/local/sphinx/etc

to enter the etc directory of sphinx

sudo cp sphinx.conf.dist sphinx.conf

to copy a configuration file and name it sphinx.conf.

Import the example.sql file in this directory into the local database named test.

Modify the configuration information and change the database connection information to your local database information.

Then use the following command to import data and generate an index:

$ cd /usr/local/sphinx/etc
$ sudo /usr/local/sphinx/bin/indexer --all

If an error is reported when executing the indexer command:

ERROR: index 'test1stemmed': sql_connect: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

It may be because of the location of mysql.sock. In this machine, the changed location is /tmp/mysql.sock ( Relevant to the settings when installing mysql), just uncomment this line in sphinx.conf (remove the # sign in front):

#sql_sock                = /tmp/mysql.sock

Execute the above indexer command again, everything is normal.

To execute the query, you can use the following command:

$ cd /usr/local/sphinx/etc
$ sudo /usr/local/sphinx/bin/search test

An error may be reported during the search process:

index 'test1': search error: query too complex, not enough stack (thread_stack=-2665032K or higher required).

I tried to modify the value of thread_stack in the searchd module in sphinx.conf, but it did not solve the problem, and then commented it out The following line in source src1

#sql_query_info         = SELECT * FROM documents WHERE id=$id

and then execute the search command, it will be OK.

Use the following command to start sphinx in the background:

$ cd /usr/local/sphinx/etc
$ sudo /usr/local/sphinx/bin/searchd

Use the php script to execute the search command. You can use the following command:

$ cd sphinx/api
$ php test.php test

The input result is as follows:

Query 'test ' retrieved 3 of 3 matches in 0.022 sec.
Query stats:
'test' found 10 times in 6 documents
Matches:
1. doc_id=1, weight=101, group_id=1, date_added=2014-01-20 10:07:37
2. doc_id=2, weight=101, group_id=1, date_added=2014-01-20 10:07:37
3. doc_id=4, weight=1, group_id=2, date_added=2014-01-20 10:07:37

4. Install coreseek

tar zxvf coreseek-4.1.tar.gz

After decompression, two directories will appear: csft -4.1, mmseg-3.2.14

Install mmseg first

cd mmseg-3.2.14/
./configure --prefix=/usr/local/mmseg

Compile if an error occurs: "config.status: error: cannot find input file: src/Makefile.in"

Solution:

sudo apt-get install automake
aclocal
libtoolize --force 我运行后有一个错误,没管它。
automake --add-missing
autoconf
autoheader
make clean
./configure --prefix=/usr/local/mmseg
make
sudo make install

Install csft( coreseek)

cd csft-4.1/
sh buildconf.sh
./configure --prefix=/usr/local/coreseek --with-mysql=/usr/local/mysql/ --with-mmseg=/usr/local/mmseg/ --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg/lib/ 
sudo make && make install

After the installation is completed, it is the same as after the installation of sphinx. You need to import the coreseek/etc/example.sql file to the local database, then copy sphinx.conf.dist to csft.conf, modify the database user name and password, and the test fails. The solution is the same as the error solution in sphinx.

To use sphinx, you need to do the following things

1. Have data;

2. Create a sphinx configuration file;

3. Generate an index;

4. Start the searchd service process, the default is 9312

5. Use PHP to connect to the sphinx service

Start sphinx

cd /usr/local/coreseek/bin/
./searchd

Start command

searchd command parameter introduction:

-c Specify the configuration file

--stop Stop the service

--pidfile is used to explicitly specify a PID file

-p specifies the port

5, php installs sphinx extension

sudo pecl install sphinx

If an error occurs: "configure: error: Cannot find libsphinxclient headers"

Solution:

cd coreseek-4.1/csft-4.1/api/libsphinxclient/
./configure --prefix=/usr/local/libsphinxclient
sudo make && make install

Solved!

Go back and continue executing

./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx=/usr/local/libsphinxclient
sudo make && make install

A message similar to "Installing shared extensions: /usr/lib/php5/20090626/sphinx.so" appears, indicating success.

You can enter the directory and you will find that a sphinx.so file has been generated

Load the so file in php.ini

extension=/usr/lib/php5/20090626/sphinx.so

Restart apache, phpinfo( ) indicates success.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn