1、coreseek centos 5.4 下 的安装
##下载coreeseek 3.2.14
wget http://www.coreseek.cn/uploads/csft/3.2/coreseek-3.2.14.tar.gz tar xzvf coreseek-3.2.14.tar.gz cd coreseek-3.2.14
##安装mmseg 输出的warning信息可以忽略,如果出现error则需要解决
cd mmseg-3.2.14 ./bootstrap ./configure --prefix=/usr/local/mmseg3 make && make install cd ..
##安装coreseek 输出的warning信息可以忽略,如果出现error则需要解决
cd csft-3.2.14 sh buildconf.sh ./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
##如果提示mysql问题,可以查看MySQL数据源安装说明
make && make install cd ..至此,安装完毕
安装过程中可能会出错:
libmysqlclient.so.16 等错误
执行下面命令即可:(注意修改mysql 的安装位置)
ln -s /usr/local/webserver/mysql/lib/mysql/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient.so.16
配置文件在 /usr/local/coreseek/etc/ 目录下
复制一份 sphinx-min.conf.dist 修改为 my.conf
修改里面的内容,根据数据库的表结构
假设我有一个电影的数据库
里面有一张表 存储电影信息的
sql 为:
CREATE TABLE `movie` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(200) DEFAULT NULL, `ename` varchar(200) DEFAULT NULL, `alias` varchar(600) DEFAULT NULL, `screenwriter` varchar(50) DEFAULT NULL, `introduction` longtext, `pubdate` datetime DEFAULT NULL, `pubdatestring` varchar(50) DEFAULT NULL, `actors` longtext, `directors` varchar(200) DEFAULT NULL, `covercode` varchar(50) DEFAULT NULL, PRIMARY KEY (`oid`), UNIQUE KEY `oid` (`oid`), UNIQUE KEY `id` (`id`) USING BTREE, KEY `pubdate` (`pubdate`) USING BTREE ) ENGINE=MyISAM DEFAULT CHARSET=utf8;name 电影名称
ename 英文名
alias 别名
introduction 介绍
假设根据这些字段进行搜索,那么配置文件内容是这样的:
配置文件,分为几个部分 :源,索引,索引器,守护进程
#源 source src_movie { type = mysql sql_host = localhost sql_user = root sql_pass = root sql_db = nm.movie sql_port = 3306 # optional, default is 3306 sql_query = \ SELECT id,UNIX_TIMESTAMP(pubdate) AS pubdated , name, ename, alias, screenwriter, actors, directors, introduction FROM movie sql_attr_timestamp = pubdated sql_query_info_pre = SET NAMES utf8 } #索引 index movie { source = src_movie path = /usr/local/coreseek/var/data/movie docinfo = extern charset_dictpath = /usr/local/mmseg3/etc/ charset_type = zh_cn.utf-8 mlock = 0 morphology = none min_word_len = 1 html_strip = 0 } #索引器 indexer { mem_limit = 128M } #守护进程 searchd { port = 9312 log = /usr/local/coreseek/var/log/searchd.log query_log = /usr/local/coreseek/var/log/query.log read_timeout = 5 max_children = 30 pid_file = /usr/local/coreseek/var/log/searchd.pid max_matches = 1000 seamless_rotate = 1 preopen_indexes = 0 unlink_old = 1 }
3、创建索引
#生成所有索引 /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/my.conf --all --rotate #索引测试 /usr/local/coreseek/bin/search -c /usr/local/coreseek/etc/my.conf 拯救大兵瑞恩 #开启守护进程,用来让 php 等程序调用 /usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/my.conf #停止守护进程 /usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/my.conf --stop
4、编写php代码