Stay hungry, Stay foolish

0%

Sphinx安装

环境

  • ubuntu12.04LTS
  • xampp for linux1.80(php5.4.4、apache2.4.2、mysql5.5.25)

安装

我下载的是Ubuntu 10.04 LTS i386 DEB

  • 安装
1
sudo dpkg -i sphinxsearch_2.0.6-release-0ubuntu11~lucid_i386.deb

如果有错误提示,安装一下依赖的包就行了

  • 文件路径

如果是源码安装的话,可以指定–prefix PATH,所有的文件都放到了指定的PATH下了.

我使用的deb包,就要用whereis查看一下它们的具体位置了。

目录 说明
/etc/sphinxsearch sphinx的配置目录
/usr/share/sphinxsearch 这个目录下只有一个api目录
/usr/bin/ indexer、search、searchd

测试

  • 导入数据
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
DROP TABLE IF EXISTS test.documents;
CREATE TABLE test.documents
(
id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,
group_id INTEGER NOT NULL,
group_id2 INTEGER NOT NULL,
date_added DATETIME NOT NULL,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL
);
REPLACE INTO test.documents ( id, group_id, group_id2, date_added, title, content ) VALUES
( 1, 1, 5, NOW(), 'test one', 'this is my test document number one. also checking search within phrases.' ),
( 2, 1, 6, NOW(), 'test two', 'this is my test document number two' ),
( 3, 2, 7, NOW(), 'another doc', 'this is another group' ),
( 4, 2, 8, NOW(), 'doc number four', 'this is to test groups' );
DROP TABLE IF EXISTS test.tags;
CREATE TABLE test.tags
(
docid INTEGER NOT NULL,
tagid INTEGER NOT NULL,
UNIQUE(docid,tagid)
);
INSERT INTO test.tags VALUES
(1,1), (1,3), (1,5), (1,7),
(2,6), (2,4), (2,2),
(3,15),
(4,7), (4,40);
  • 编辑配置
1
sudo vim /etc/sphinxsearch/sphinx.conf

设置sql_user和sql_pass

因为我使用的个集成环境包,所以还要指定一下sql_sock

其它按默认配置就好了。

  • 生成索引
1
sudo indexer test1

  • 命令行测试
1
search -i test1 -q test

  • api测试
1
2
cd /usr/share/sphinxsearch/api/
/opt/lampp/bin/php test.php test

问题

  • search error

网上的教程大都是执行search “test”进行测试,但是运行后却报错了:

using config file '/etc/sphinxsearch/sphinx.conf'...
index 'test1': search error: .

这样没有错误信息的提示很是让人郁闷,最后在这里sphinx官方的社区(原文链接)里找到了答案,就是在上面命令行测试时用到的语句。

据说打赏我的人,代码没有BUG