With the increasing number of movie website resources, increasing the number of movie resource search services becomes inevitable. The direct operation of database search reduces the search performance by increasing IO port requests. In the previous project, there was a basis for the use of sphsearch. In addition, the Chinese search service was supported. Finally, we decided to use the sphinx-based Coreseek search service.
Download and install [I use mysql 4.1 in linux, and the system supports mysql and xml data sources ]:
-
Coreseek, download coreseek-4.1-beta.tar.gz package
-
Unzip the gz package, tar zxvf coreseek-4.1-beta.tar.gz
-
Compile and install mmseg [Chinese word segmentation package]
-
./Bootstrap
-
./Configure -- prefix =/usr/local/mmseg3
-
Make & make install
-
Compile and install coreseek
-
Sh buildconf. sh # The output warning information can be ignored. If an error occurs, it must be resolved.
-
. /Configure -- prefix =/usr/local/coreseek -- without-unixodbc -- with-mmseg-separated des =/usr/local/mmseg3/include/mmseg/--- mmseg-libs =/usr/local/mmseg3/lib/-- with-mysql # with-mmseg-libs is the mmseg Chinese word segmentation path
-
Make & make install
The update cycle of a movie website is relatively long. sphsf-indexing adopts the primary index + incremental index method, and then merges the two index files. Deploy your own search configuration file as follows:
-
Go to The etc file under the coreseek installation directory and create or modify the. conf configuration file.
-
Configure source
-
Source movie
{
Type = mysql
SQL _host = localhost # mysql database host
SQL _user = root # mysql User
SQL _pass = # mysql User password
SQL _db = movie # movie
SQL _port = 3306 # optional, default is 3306
SQL _query_pre = SET NAMES utf8
# Create an incremental index
SQL _query_pre = REPLACE INTO movie_sph_counter SELECT 1, MAX (id) FROM movie
SQL _query = SELECT id, UNIX_TIMESTAMP (cdate) AS date, id AS movie_id, name, year, type, status, sync_status FROM movie WHERE id <= (SELECT max_movie_id FROM movie_sph_counter WHERE counter_id = 1)
# Search for returned fields
SQL _attr_uint = movie_id
SQL _attr_uint = year
SQL _attr_uint = type
SQL _attr_uint = date
SQL _attr_uint = status
SQL _attr_uint = sync_status
SQL _field_string = name
SQL _query_info_pre = SET NAMES utf8 # SET the correct character SET during command line query
SQL _query_info = SELECT * FROM movie WHERE id = $ id # When querying through the command line, read the original data FROM the database
}
# Incremental Index Source
Source delta: movie
{
SQL _query_pre = SET NAMES utf8
SQL _query = SELECT id, UNIX_TIMESTAMP (cdate) AS date, id AS movie_id, name, year, type, status, sync_status FROM movie WHERE id> (SELECT max_movie_id FROM movie_sph_counter WHERE counter_id = 1)
SQL _query_post_index = REPLACE INTO movie_sph_counter SELECT 1, MAX (id) FROM movie
}
-
Configure indexes
-
# Index definition
Index movie
{
Source = movie # corresponding source name
Path =/usr/local/coreseek/var/data/movie # change it to the actual absolute path, for example,/usr/local/coreseek/var /...
Docinfo = extern
Mlock = 0
Morphology = none
Min_word_len = 1
Html_strip = 0
# Chinese word segmentation configuration, for details, see: http://www.coreseek.cn/products-install/coreseek_mmseg/
Charset_dictpath =/usr/local/mmseg/etc/# BSD, set in Linux environment,/mmseg path at the end of symbol
Charset_type = zh_cn.utf-8 # Chinese encoding
}
Index delta: movie
{
Source = delta
Path =/usr/local/coreseek/var/data/movie_delta # note !! Do not use the same name as the primary index path
Docinfo = extern
Mlock = 0
Morphology = none
Min_word_len = 1
Html_strip = 0
Charset_dictpath =/usr/local/mmseg/etc/
Charset_type = zh_cn.utf-8
}
-
Configure search service
-
# Searchd service definition
Searchd
{
Listen = 9312 # port number, which can be customized
Read_timeout = 5
Max_children = 30
Max_matches = 1000
Seamless_rotate = 0
Preopen_indexes = 0
Unlink_old = 1
Compat_sphinxql_magics = 0
Pid_file =/usr/local/coreseek/var/log/searchd_mysql.pid # change it to the actual absolute path, for example,/usr/local/coreseek/var /...
Log =/usr/local/coreseek/var/log/searchd_mysql.log # change it to the actual absolute path, for example,/usr/local/coreseek/var /...
Query_log =/usr/local/coreseek/var/log/query_mysql.log # change it to the actual absolute path, for example,/usr/local/coreseek/var /...
Binlog_path = # Disable binlog
}
-
Run the command to create an index:/usr/local/coreseek/bin/indexer-c movie. conf -- all
-
Start the search service running in the background:/usr/local/coreseek/bin/searchd-c movie. conf
-
Create a scheduled task and run the incremental index:/usr/local/coreseek/bin/indexer-c csft_movie.conf delta -- rotate
-
Create a scheduled task and merge indexes:/usr/local/coreseek/bin/indexer-c csft_movie.conf -- merge movie delta -- merge-dst-range deleted 0 0 -- rotate
-
So far, the search service based on sphsf-+ mysql has been set up. The next step is to develop the search interface code according to sphinxapi. php ......
The first time you build your own sphinx search service, and finally test the website search speed.
I would like to share with you the hope to help you