Heim >Backend-Entwicklung >PHP-Tutorial >sphinx coreseek 初探_PHP教程
遇到了一些问题也都在上面的网站中找到了答案
下面是我的索引配置文件mysql.conf的内容
[php]
source mysql
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = mfy
sql_db = zlk
sql_port = 3306
sql_query_pre = SET NAMES utf8
sql_query = SELECT id,pic_id,city,captionwriter,countryname,title,description,contenttype,generator,author,keyword,language,datecreatedline FROM picture_info
#sql_query第一列id需为整数
#title、content作为字符串/文本字段,被全文索引
# sql_attr_uint = id #从SQL读取到的值必须为整数
sql_attr_uint = pic_id #从SQL读取到的值必须为整数
sql_attr_timestamp = datecreatedline #从SQL读取到的值必须为整数,作为时间属性
# sql_attr_str2ordinal = title
}
#index定义
index mysql
{
source = mysql #对应的source名称
path = /usr/local/coreseek/var/data/mysql
docinfo = extern
mlock = 0
morphology = none
min_word_len = 1
min_infix_len =1
html_strip = 0
charset_dictpath = /usr/local/mmseg3/etc/ #BSD、Linux环境下设置,/符号结尾
#charset_dictpath = etc/ #Windows环境下设置,/符号结尾
charset_type = zh_cn.utf-8
}
#全局index定义
indexer
{
mem_limit = 2G
}
searchd
{
listen = 9312
max_matches = 10000
pid_file = /usr/local/coreseek/var/log/searchd_mysql.pid
log = /usr/local/coreseek/var/log/searchd_mysql.log
query_log = /usr/local/coreseek/var/log/query_mysql.log
}
source mysql
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = mfy
sql_db = zlk
sql_port = 3306
sql_query_pre = SET NAMES utf8
sql_query = SELECT id,pic_id,city,captionwriter,countryname,title,description,contenttype,generator,author,keyword,language,datecreatedline FROM picture_info
#sql_query第一列id需为整数
#title、content作为字符串/文本字段,被全文索引
# sql_attr_uint = id #从SQL读取到的值必须为整数
sql_attr_uint = pic_id #从SQL读取到的值必须为整数
sql_attr_timestamp = datecreatedline #从SQL读取到的值必须为整数,作为时间属性
# sql_attr_str2ordinal = title
}
#index定义
index mysql
{
source = mysql #对应的source名称
path = /usr/local/coreseek/var/data/mysql
docinfo = extern
mlock = 0
morphology = none
min_word_len = 1
min_infix_len =1
html_strip = 0
charset_dictpath = /usr/local/mmseg3/etc/ #BSD、Linux环境下设置,/符号结尾
#charset_dictpath = etc/ #Windows环境下设置,/符号结尾
charset_type = zh_cn.utf-8
}
#全局index定义
indexer
{
mem_limit = 2G
}
searchd
{
listen = 9312
max_matches = 10000
pid_file = /usr/local/coreseek/var/log/searchd_mysql.pid
log = /usr/local/coreseek/var/log/searchd_mysql.log
query_log = /usr/local/coreseek/var/log/query_mysql.log
}
写好索引文件后需要建立索引,然后再建立进程就可以使用php的api了。
建立索引的命令:
/usr/local/coreseek/bin/indexer -c etc/mysql.conf mysql
/usr/local/coreseek/bin/indexer -c 索引配置文件地址 索引名字
如果需要重新建立索引则要在上面语句的最后加上 --rotate 参数
/usr/local/coreseek/bin/indexer -c etc/mysql.conf mysql --rotate
使用命令搜索:
/usr/local/coreseek/bin/search -c etc/mysql.conf "测试"
/usr/local/coreseek/bin/indexer -c 索引配置文件地址 要搜索的关键字
启动服务进程:
/usr/local/coreseek/bin/searchd -c etc/mysql.conf
我测试的时候只能建立一个服务想建立另一个服务的时候需要将上一个服务关掉才行
例如我现在已经开启了一个服务服务 是csft.conf 的,那么我用
ps -ef | grep core
可以看到结果中有
root 11730 1 0 14:33 pts/0 00:00:00 /usr/local/coreseek/bin/searchd -c etc/csft.conf
这个一行,这时就需要先关掉csft.conf才行
/usr/local/coreseek/bin/searchd -c etc/csft.conf --stop
这是才可以重新建立mysql.conf 的服务