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: Install Coreseek Chinese search engine, configure MySQL database access interface, use PHP program to achieve Chinese search.
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 actions:
One, install the compilation tool
Yum install make gcc g++ gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel
Second, install Coreseek
1, download Coreseek
Download Address: 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 the 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 there is error, you need to solve
./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 the following figure
/usr/local/mmseg3/bin/mmseg-d/usr/local/mmseg3/etc/usr/local/src/coreseek-3.2.14/testpack/var/test/test.xml
System Yun-wei Www.111cn.net 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 Network 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 indexes
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 database to MySQL from 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 #拷贝MySQL数据源配置文件
Ln-s/usr/local/coreseek/etc/csft_mysql.conf/etc/csft_mysql.conf #添加软连接
vi/etc/csft_mysql.conf #编辑, modify
###############################################################################
For more information #MySQL数据源配置, please see: http://www.coreseek.cn/products-install/mysql/
#请先将var/test/documents.sql to 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, Full-text indexed
Sql_attr_uint = group_id #从SQL读取到的值必须为整数
Sql_attr_timestamp = date_added #从SQL读取到的值必须为整数, as time attribute
Sql_query_info_pre = set NAMES UTF8 #命令行查询时, setting the correct character set
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 #中文分词配置, please see: http://www.coreseek.cn/products-install/coreseek_mmseg/
Charset_dictpath = /usr/local/mmseg3/etc/ #BSD, Linux environment settings,/end of symbol
#charset_dictpath = etc/#Windows环境下设置,/symbol end, best given 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 test files 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 test files to the Web site root directory
cd/usr/local/nginx/html #进入web站点根目录
VI test.php #编辑, add the following code
#################################################################################
<?php
Note that the encoding format of the file needs to be saved in UTF-8 format
Require ("sphinxapi.php");
$CL = new Sphinxclient ();
$cl->setserver (' 127.0.0.1 ', 9312);
The following settings are used to return the results of the array form
$cl->setarrayresult (TRUE);
/*
Filtering of IDs
$CL->setidrange (3,4);
Sql_attr_uint types of property fields, which need to be filtered using setfilter, like SQL where group_id=2
$cl->setfilter (' group_id ', Array (2));
Sql_attr_uint types of property fields, you can also set the filter scope, similar to the SQL where group_id2>=6 and group_id2<=8
$cl->setfilterrange (' Group_id2 ', 6,8);
*/
Take the first 20 data from scratch, 0,20 limit similar to SQL statements 0,20
$CL->setlimits (0,20);
When indexing, there are no fields for the Sql_attr_ type setting, and can be used as a "search string" for Full-text search
$res = $cl->query (' Search string ', ' * '); "*" means searching all indexes at the same time, "index name (such as test or Test,test2)" indicates the search for the specified
If you need to search for content that specifies a full text segment, you can use an 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 Browser test: As shown in the following figure
http://192.168.21.127/test.php
System Yun-wei Www.111cn.net 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 up Coreseek automatic background operation
Vi/etc/rc.d/rc.local #编辑, add the following code on 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 on the last line
*/30 * * * * root/usr/local/coreseek/bin/build_index.sh #每隔30分钟执行一次
: wq! #保存退出
service crond reload &NBSP; #重新加载任务计划