Phpcms sphinx full-text index tutorial
English introduction: http://www.sphinxsearch.com/docs/manual-0.9.9.html
1. First install sphinx on the server
Install sphinx on Windows
1. Download package http://www.sphinxsearch.com/downloads/sphinx-0.9.9-win32.zip that supports mysql
2. Decompress the sphinx-0.9.9-win32.zip to D: \ sphinx
3. Install the sphinx service and run the command on the command line.
D: \ sphinx \ searchd-install-config d: \ sphinx. conf-servicename SphinxSearch
Http://www.sphinxsearch.com/docs... # Installing-windows
1. Download source package http://www.sphinxsearch.com/downloads/sphinx-0.9.9.tar.gz
$ Tar xzvf sphinx-0.9.8.tar.gz
$ Cd sphinx
$./Configure-prefix =/usr/local/sphure-with-mysql =/usr/local/mysql
$ Make
$ Make install
FAQ 1
/Usr/local/sph1_- 0.9.9/src/sph1_. cpp: 20060: undefined reference to libiconv_open'
/Usr/local/sph1_- 0.9.9/src/sph1_. cpp: 20078: undefined reference to libiconv'
/Usr/local/sph1_- 0.9.9/src/sph1_. cpp: 20084: undefined reference to libiconv_close'
Collect2: ld returned 1 exit status
Make [2]: *** [indexer] Error 1
Make [2]: Leaving directory/home/jling/sph1_- 0.9.9/src'
Make [1]: *** [all] Error 2
Make [1]: Leaving directory '/home/jling/sph1_- 0.9.9/src'
Make: *** [all-recursive] Error 1
Solution: Open the configure file, find "# define USE_LIBICONV 1", remove the comment, and change 1 to 0.
FAQ 2
Error while loading shared libraries: libmysqlclient. so.16: cannot open shared object file: No such file or directory
Solution:
64-bit system ln-s/usr/local/webserver/mysql/lib/mysql/libmysqlclient. so.16.0.0/usr/lib64/libmysqlclient. so.16
32-bit system ln-s/usr/local/webserver/mysql/lib/mysql/libmysqlclient. so.16.0.0/usr/lib/libmysqlclient. so.16
Sphexample. conf
Source main
{
Type = mysql # Database type
SQL _host = 10.228.134.211 # Database ip address
SQL _user = admin # Database username
SQL _pass = admin # database password
SQL _db = phpcms_v9 # Database name
SQL _port = 3306 # Database Port
SQL _query_pre = SET NAMES utf8
SQL _query_pre = REPLACE INTO v9_sphinx_counter SELECT 1, MAX (searchid) FROM v9_search
SQL _query = SELECT searchid, adddate, siteid, typeid, id, data FROM v9_search \
WHERE searchid> = $ start AND searchid <= $ end
SQL _query_range = SELECT 1, max_doc_id FROM v9_sphinx_counter WHERE counter_id = 1
SQL _range_step = 5000
# Used for string attribute setting, filtering, and sorting
SQL _attr_uint = typeid
SQL _attr_uint = siteid
SQL _attr_uint = id
SQL _attr_timestamp = adddate
SQL _query_info = SELECT * FROM v9_search WHERE searchid = $ id
}
Source delta
{
Type = mysql # Database type
SQL _host = 10.228.134.211 # Database ip address
SQL _user = admin # Database username
SQL _pass = admin # database password
SQL _db = phpcms_v9 # Database name
SQL _port = 3306 # Database Port
SQL _query_pre = SET NAMES utf8
SQL _query = SELECT searchid, adddate, siteid, typeid, id, data FROM v9_search \
WHERE searchid> (SELECT max_doc_id FROM v9_sphinx_counter WHERE counter_id = 1)
SQL _query_post = REPLACE INTO v9_sphinx_counter SELECT 1, MAX (searchid) FROM v9_search
# Used for string attribute setting, filtering, and sorting
SQL _attr_uint = typeid
SQL _attr_uint = siteid
SQL _attr_uint = id
SQL _attr_timestamp = adddate
SQL _query_info = SELECT * FROM v9_search WHERE searchid = $ id
}
# Primary index
Index main
{
Source = main
# Index Directory
Path = D: \ sphinx \ data \ main
# Encoding
Charset_type = UTF-8
# UTF-8 encoding table
Charset_table = 0 .. 9, .. z-> .. z, _, .. z, U + 410 .. U + 42F-> U + 430 .. U + 44F, U + 430 .. U + 44F
# Simple Word Segmentation: only 0 and 1 are supported. To search for Chinese characters, specify 1
Ngram_len = 1
# Characters to be segmented. If you want to search for Chinese characters, remove the preceding comments.
Ngram_chars = U + 3000 .. U + 2FA1F
}
# Incremental index
Index delta
{
Source = delta
Path = D: \ sphinx \ data \ delta
# Encoding
Charset_type = UTF-8
# UTF-8 encoding table
Charset_table = 0 .. 9, .. z-> .. z, _, .. z, U + 410 .. U + 42F-> U + 430 .. U + 44F, U + 430 .. U + 44F
# Simple Word Segmentation: only 0 and 1 are supported. To search for Chinese characters, specify 1
Ngram_len = 1
# Characters to be segmented. If you want to search for Chinese characters, remove the preceding comments.
Ngram_chars = U + 3000 .. U + 2FA1F
}
Indexer
{
Mem_limit = 128 M
}
Searchd
{
Port = 9312
Log = D: \ sphinx \ data \ phpcms \ searchd. log
Query_log = D: \ sphinx \ data \ phpcms \ query. log
Read_timeout = 5
Max_children = 30
Pid_file = D: \ sphinx \ data \ phpcms \ searchd. pid
Max_matches = 2000
Seamless_rotate = 0
Preopen_indexes = 0
Unlink_old = 1
}
Attachment: Set index update for scheduled tasks
1. windows
Scheduled tasks need to be set
# Merge indexes at A.M. and execute merge. bat.
# Update the index every minute for the rest of the time and execute delta. bat
Merge. bat
@ ECHO off
D: \ sphinx \ bin \ indexer.exe-config D: \ sphinx. conf-merge main delta-rotate
Echo indexing, window will close when complete
Delta. bat
@ ECHO off
D: \ sphinx \ bin \ indexer.exe-config D: \ sphinx. conf delta-rotate
Echo indexing, window will close when complete
2. Edit the scheduled task crontab-e in linux.
# Merge indexes at AM, and update indexes every minute for the rest of the time
* 0-3 ***/usr/local/sphinx/bin/indexer-config/usr/local/sphinx/etc/sphinx. conf delta-rotate
* 6-23 ***/usr/local/sphinx/bin/indexer-config/usr/local/sphinx/etc/sphinx. conf delta-rotate
0 4 ***/usr/local/sphinx/bin/indexer-config/usr/local/sphinx/etc/sphinx. conf-merge main delta-rotate
Various paths and permissions must be consistent with the server where the application is located, for example:
Required in sphworker. conf
SQL _host database host address
SQL _user database username
SQL _pass database password
SQL _db database name
SQL _port database Port
Phpcms _
Index path D: \ sphinx \ data \ delta