Sphinx 学习2

接上篇,这样有个延续,对自己以后再看这些东西也会有个启发:

首先来看配置文件:1、sphinx.conf.in 2、sphinx.conf;这两个配置文件是一样的,在1中已经提到,sphinx.conf是由sphinx.conf.in拷贝过去的,对里面的相对路径进行了绝对化;同样在in中,也要对路径进行绝对化,不然不能记录日志,所注册的服务也不能正常启动;以下贴也修改后的配置文件

#
# Minimal Sphinx configuration sample (clean, simple, functional)
#

source src1
{
type            = mysql

sql_host        = localhost
sql_user        = root
sql_pass        = a123456
sql_db            = test
sql_port        = 3306    # optional, default is 3306

sql_query        = \
SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \
FROM documents

sql_attr_uint        = group_id
sql_attr_timestamp    = date_added

sql_query_info        = SELECT * FROM documents WHERE id=$id
}

index test1
{
source            = src1
path            = F:/sphinx-2.0.3-win32/data/test1
docinfo            = extern
charset_type        = sbcs
}

index testrt
{
type            = rt
rt_mem_limit        = 32M

path            = F:/sphinx-2.0.3-win32/data/testrt
charset_type        = utf-8

rt_field        = title
rt_field        = content
rt_attr_uint        = gid
}

indexer
{
mem_limit        = 32M
}

searchd
{
listen            = 9312
listen            = 9306:mysql41
log            = F:/sphinx-2.0.3-win32/log/searchd.log
query_log        = F:/sphinx-2.0.3-win32/log/query.log
read_timeout        = 5
max_children        = 30
pid_file        = F:/sphinx-2.0.3-win32/log/searchd.pid
max_matches        = 1000
seamless_rotate        = 1
preopen_indexes        = 1
unlink_old        = 1
workers            = threads # for RT to work
}

 

接下来,再明白一个问题,下面这段代码是注册一个服务,服务的名称叫SphinxSearch,服务的命令就是searchd –config c:\Sphinx\sphinx.conf.in;查看服务就可以看到

F:\sphinx-2.0.3-win32\bin>searchd –install –config F:\sphinx-2.0.3-win32\bin\sphinx.conf.in –servicename SphinxSearch

image

既然windows服务可以注册,当然也可以删除,我在网上查了下,所有命令都在windows中的sc中

sc delete SphinxSearch

这样,在每次启动windows的时候,就可以自动启动SphinxSearch进程,进程端口9312,可以通过telnet命令测试启动是否成功

telnet localhost 9312

最后一步,使用代码测试是否可以使用,测试代码已经在api文件夹里了,里面有各种语言的测试demo,我们使用php文件来测试,把sphinxapi.php和test.php都拷贝到F:\wamp\bin\php\php5.3.5目录(如果设置了 php执行路径不需要这样做)执行下面的命令,并得到如下结果,则说明测试成功,进程已经在监控状态了

F:\wamp\bin\php\php5.3.5>php test.php test
Query ‘test ‘ retrieved 3 of 3 matches in 0.032 sec.
Query stats:
‘test’ found 5 times in 3 documents

Matches:
1. doc_id=1, weight=101, group_id=1, date_added=2012-01-13 05:47:21
2. doc_id=2, weight=101, group_id=1, date_added=2012-01-13 05:47:21
3. doc_id=4, weight=1, group_id=2, date_added=2012-01-13 05:47:21

发表评论

邮箱地址不会被公开。