站长论坛

标题: 初试MYSQL全文检索工具——Sphinx [打印本页]

作者: tznktg    时间: 2008-11-5 10:26
标题: 初试MYSQL全文检索工具——Sphinx
参考文章:
用 PHP 构建自定义搜索引擎
Sphinx速成指南

测试环境


操作系统:windows xp
数据库版本:MYSQL Server version          5.0.45




一、安装
    详细安装过程参考Sphinx速成指南

二、测试sphinx自带的demo。
  1、导入数据库文件example.sql。
      该文件在test数据库新建立一个documents,并插入基本的测试数据。
  2、修改sphinx.conf.in文件的配置参数,并保存为sphinx.conf文件。

主要修改以下几个参数
第一、连接数据库的用户名和密码


        sql_user        = root
  sql_pass        = ***** #你自己的密码


第二、索引路径


path      = E:/web/sphinx/data/test1#改为自己的路径



    3、建立索引
bin/indexer.exe是建立索引的程序,具体参数可以在命令行下查看帮助。


E:\web\sphinx>bin\indexer --config sphinx.conf test1
Sphinx 0.9.8-release (r1371)
Copyright (c) 2001-2008, Andrew Aksyonoff

using config file 'sphinx.conf'...
indexing index 'test1'...
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 193 bytes
total 0.127 sec, 1521.85 bytes/sec, 31.54 docs/sec


    4、开启查询的守护进程


E:\web\sphinx>bin\searchd --config sphinx.conf
Sphinx 0.9.8-release (r1371)
Copyright (c) 2001-2008, Andrew Aksyonoff

WARNING: forcing --console mode on Windows
using config file 'sphinx.conf'...
WARNING: index 'test1stemmed': preload: failed to open @CONFDIR@/data/test1stemm
ed.sph: No such file or directory; NOT SERVING
WARNING: index 'dist1': no such local index 'test1stemmed' - SKIPPING LOCAL INDE
X
creating server socket on 0.0.0.0:3312
accepting connections


注意开启3312端口,并修改相应的参数
    5、查询测试。
查询了两次,分别是ggart和another。结合数据库查看,结果是正确的。



E:\web\sphinx>bin\search -c sphinx.conf ggart
Sphinx 0.9.8-release (r1371)
Copyright (c) 2001-2008, Andrew Aksyonoff

using config file 'sphinx.conf'...
index 'test1': query 'ggart ': returned 0 matches of 0 total in 0.000 sec

words:
1. 'ggart': 0 documents, 0 hits

index 'test1stemmed': search error: failed to open @CONFDIR@/data/test1stemmed.s
ph: No such file or directory.

E:\web\sphinx>bin\search -c sphinx.conf another
Sphinx 0.9.8-release (r1371)
Copyright (c) 2001-2008, Andrew Aksyonoff

using config file 'sphinx.conf'...
index 'test1': query 'another ': returned 1 matches of 1 total in 0.000 sec

displaying matches:
1. document=3, weight=2, group_id=2, date_added=Tue Aug 05 17:22:06 2008
        id=3
        group_id=2
        group_id2=7
        date_added=2008-08-05 17:22:06
        title=another doc
        content=this is another group

words:
1. 'another': 1 documents, 2 hits

index 'test1stemmed': search error: failed to open @CONFDIR@/data/test1stemmed.s
ph: No such file or directory.
TAG: mysql MySQL Mysql Sphinx 检索工具 MYSQL 全文 初试




欢迎光临 站长论坛 (http://tzlink.com/bbs/) Powered by Discuz! X3.2