參考文章:
用 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.