Description
Operating system: CentOS 5.X
Server IP Address: 192.168.21.127
Web environment: Nginx+php+mysql
Site root directory:/usr/local/nginx/html
Objective: to install the Coreseek Chinese search engine, configure the MySQL database access interface, and implement the Chinese search using PHP program.
Coreseek Official website:
http://www.coreseek.cn/
http://www.coreseek.cn/products/=%22/products-install/step_by_step/
http://www.coreseek.cn/products-install/mysql/
Specific operation:
First, install the compilation tool
Yum install make gcc g++ gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel
Second, installation Coreseek
1. Download Coreseek
: http://www.coreseek.cn/uploads/csft/3.2/coreseek-3.2.14.tar.gz
Upload coreseek-3.2.14.tar.gz to/usr/local/src directory
2, Installation Mmseg
Cd/usr/local/src
Tar zxvf coreseek-3.2.14.tar.gz #解压
CD coreseek-3.2.14
CD mmseg-3.2.14
./bootstrap #输出的warning信息可以忽略, if error occurs, you need to resolve
./configure--prefix=/usr/local/mmseg3 #配置
Make #编译
Make install #安装
3, Installation Coreseek
Cd/usr/local/src
CD coreseek-3.2.14
CD csft-3.2.14
SH buildconf.sh #输出的warning信息可以忽略, if error occurs, you need to resolve
./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 #安装
Third, test mmseg participle, coreseek search, MySQL data source
Cd/usr/local/src
CD coreseek-3.2.14
CD Testpack
Cat/usr/local/src/coreseek-3.2.14/testpack/var/test/test.xml #此时应该正确显示中文 as shown in
/usr/local/mmseg3/bin/mmseg-d/usr/local/mmseg3/etc/usr/local/src/coreseek-3.2.14/testpack/var/test/test.xml
System operation and maintenance www.osyunwei.com warm reminder: qihang01 original content copyright, reproduced please indicate the source and the original link
/usr/local/coreseek/bin/indexer-c/usr/local/src/coreseek-3.2.14/testpack/etc/csft.conf--all
/usr/local/coreseek/bin/search-c/usr/local/src/coreseek-3.2.14/testpack/etc/csft.conf Web Search
/usr/local/coreseek/bin/indexer-c/usr/local/coreseek/etc/sphinx-min.conf.dist
/usr/local/coreseek/bin/indexer-c/usr/local/src/coreseek-3.2.14/testpack/etc/csft.conf--all--rotate #启动服务, updating index
To test the MySQL data source:
Test database Download: Http://www.coreseek.cn/uploads/csft/test/documents.sql
Upload documents.sql to/usr/local/src directory
Import the database to MySQL from the server:
Mysql-u root-p #进入MySQL控制台
Create database documents; #创建数据库
Use Documents #进入数据库
Source/usr/local/src/documents.sql #导入备份文件到数据库
Exit #退出MySQL控制台
Cp/usr/local/src/coreseek-3.2.14/testpack/etc/csft_mysql.conf/usr/local/coreseek/etc/csft_mysql.conf # Copy MySQL data source configuration file
Ln-s/usr/local/coreseek/etc/csft_mysql.conf/etc/csft_mysql.conf #添加软连接
vi/etc/csft_mysql.conf #编辑, modify
###############################################################################
#MySQL数据源配置, for more information, see: http://www.coreseek.cn/products-install/mysql/
#请先将var/test/documents.sql Import the database and configure the following MySQL user password database
#源定义
SOURCE MySQL
{
Type = MySQL
Sql_host = localhost
Sql_user = root #账号
Sql_pass =123456 #密码
sql_db = Documents #MySQL数据库名称
Sql_port = 3306
Sql_query_pre = SET NAMES UTF8
Sql_query = SELECT ID, group_id, Unix_timestamp (date_added) as date_added, title, content from documents
#sql_query第一列id需为整数
#title, content as a string/text field, indexed by the full text
Sql_attr_uint = group_id #从SQL读取到的值必须为整数
Sql_attr_timestamp = date_added #从SQL读取到的值必须为整数, as a time attribute
Sql_query_info_pre = set NAMES UTF8 #命令行查询时, setting the correct character sets
Sql_query_info = SELECT * from documents WHERE id= $id #命令行查询时 to read raw data information from the database
}
#index定义
Index MySQL
{
Source = MySQL #对应的source名称
Path =/usr/local/coreseek/var/data/mysql #请修改为实际使用的绝对路径, for example:/usr/local/coreseek/var/...
DocInfo = extern
Mlock = 0
Morphology = None
Min_word_len = 1
Html_strip = 0
#中文分词配置, for more information, see: http://www.coreseek.cn/products-install/coreseek_mmseg/
Charset_dictpath =/usr/local/mmseg3/etc/#BSD, settings under Linux,/end of symbol
#charset_dictpath = etc/#Windows环境下设置,/end of symbol, it is best to give absolute path, for example: c:/usr/local/coreseek/etc/...
Charset_type = Zh_cn.utf-8
}
#全局index定义
Indexer
{
Mem_limit = 1024M #内存使用限制
Max_iops = 100
Max_iosize = 0
}
#searchd服务定义
Searchd
{
Listen = 9312
Read_timeout = 5
Max_children = 30
max_matches = 1000
Seamless_rotate = 0
preopen_indexes = 0
Unlink_old = 1
Pid_file =/usr/local/coreseek/var/log/searchd_mysql.pid #请修改为实际使用的绝对路径, for example:/usr/local/coreseek/var/...
Log =/usr/local/coreseek/var/log/searchd_mysql.log #请修改为实际使用的绝对路径, for example:/usr/local/coreseek/var/...
Query_log =/usr/local/coreseek/var/log/query_mysql.log #请修改为实际使用的绝对路径, for example:/usr/local/coreseek/var/...
}
#################################################################################
: wq! #保存退出
cp/usr/local/src/coreseek-3.2.14/testpack/api/sphinxapi.php/usr/local/nginx/html/sphinxapi.php # Copy the test file to the Web site root directory
cp/usr/local/src/coreseek-3.2.14/testpack/api/test_coreseek.php/usr/local/nginx/html/test_coreseek.php # Copy the test file to the Web site root directory
Cd/usr/local/nginx/html #进入web站点根目录
VI test.php #编辑, add the following code
#################################################################################
<?php
Note the encoding format of the file needs to be saved as UTF-8 format
Require ("sphinxapi.php");
$CL = new Sphinxclient ();
$cl->setserver (' 127.0.0.1 ', 9312);
The following settings are used to return the result in array form
$cl->setarrayresult (TRUE);
/*
Filtering of IDs
$CL->setidrange (3,4);
Sql_attr_uint and other types of attribute fields that need to be filtered using setfilter, SQL-like where group_id=2
$cl->setfilter (' group_id ', Array (2));
Sql_attr_uint and other types of attribute fields, you can also set the filter range, similar to the SQL where group_id2>=6 and group_id2<=8
$cl->setfilterrange (' Group_id2 ', 6,8);
*/
Take the first 20 data from the beginning, 0,20 the limit 0,20 similar to the SQL statement
$CL->setlimits (0,20);
When indexing is done, there are no fields for the Sql_attr_ type setting and can be searched as "search string" for full-text search
$res = $cl->query (' Search string ', ' * '); "*" means searching all indexes at the same time, "index name (e.g. test or test,test2)" means searching for the specified
If you need to search for the contents of a specified whole-text segment, you can use the extended match pattern:
$CL->setmatchmode (sph_match_extended);
$res =cl->query (' @title (Test) ', ' * ');
$res =cl->query (' @title (test) @content (' Network ') ', ' * ');
Echo ' <pre> ';
Print_r ($res [' matches ']);
Print_r ($res);
Print_r ($cl->getlasterror ());
Print_r ($cl->getlastwarning ());
Echo ' </pre> ';
?>
###############################################################################
: wq! #保存退出
/usr/local/coreseek/bin/indexer-c/usr/local/coreseek/etc/csft_mysql.conf--all--rotate #建立索引服务
/usr/local/coreseek/bin/searchd-c/usr/local/coreseek/etc/csft_mysql.conf--console #启动测试模式
/usr/local/coreseek/bin/searchd-c/usr/local/coreseek/etc/csft_mysql.conf #后台启动模式
/usr/local/coreseek/bin/searchd-c/usr/local/coreseek/etc/csft_mysql.conf--stop #停止
/usr/local/coreseek/bin/indexer-c/usr/local/coreseek/etc/csft_mysql.conf--all--rotate #更新索引服务
Open the browser test: as shown in
http://192.168.21.127/test.php
System operation and maintenance www.osyunwei.com warm reminder: qihang01 original content copyright, reproduced please indicate the source and the original link
http://192.168.21.127/test_coreseek.php
Four, set Coreseek boot automatic background run
Vi/etc/rc.d/rc.local #编辑, add the following code to the last line
/usr/local/coreseek/bin/searchd-c/usr/local/coreseek/etc/csft_mysql.conf
: wq! #保存退出
Vi/usr/local/coreseek/bin/build_index.sh #添加以下更新索引脚本
#!/bin/sh
/usr/local/coreseek/bin/indexer-c/usr/local/coreseek/etc/csft_mysql.conf--all--rotate
: wq! #保存退出
chmod +x/usr/local/coreseek/bin/build_index.sh #添加脚本执行权限
Vi/etc/crontab #编辑, add the following code to the last line
*/30 * * * * * root/usr/local/coreseek/bin/build_index.sh #每隔30分钟执行一次
: wq! #保存退出
Service Crond Reload #重新加载任务计划
At this point, the Linux php+mysql+coreseek Chinese search engine configuration is complete.
Reproduced in http://www.osyunwei.com/archives/7496.html
Php+mysql+coreseek Chinese search engine configuration under Linux